Sha256: 3fac10545c48fd6e21bc755e0b23c401be11cb471f7c19e5d61ee735e2d51d52

Contents?: true

Size: 1.61 KB

Versions: 132

Compression:

Stored size: 1.61 KB

Contents

unit uNucleotideCount;

interface
uses SysUtils, System.Generics.Collections;

type
  EInvalidNucleotideException = class(Exception);

  TDNA = class
  private
    fNucleotideCounts: TDictionary<char, integer>;
    function GetNucleotideCounts: TDictionary<char, integer>;
  public
    constructor create(aSequence: string);
    destructor destroy;
    function Count(aChar: char): integer;
    property NucleotideCounts: TDictionary<char, integer> read GetNucleotideCounts;
  end;

implementation


constructor TDNA.create(aSequence: string);
var NucleotideList: TList<TPair<char, integer>>;
    charInSequence: char;
    count: integer;
begin
  NucleotideList := TList<TPair<char, integer>>.Create;
  NucleotideList.Add(TPair<char, integer>.Create('A', 0));
  NucleotideList.Add(TPair<char, integer>.Create('T', 0));
  NucleotideList.Add(TPair<char, integer>.Create('C', 0));
  NucleotideList.Add(TPair<char, integer>.Create('G', 0));
  fNucleotideCounts := TDictionary<char, integer>.create(NucleotideList);

  for charInSequence in aSequence do
  begin
    if fNucleotideCounts.ContainsKey(charInSequence) then
    begin
      count := fNucleotideCounts[charInSequence];
      inc(count);
      fNucleotideCounts[charInSequence] := count;
    end;
  end;
end;

destructor TDNA.Destroy;
begin
  fNucleotideCounts.Free;
end;

function TDNA.GetNucleotideCounts: TDictionary<char, integer>;
begin
  result := fNucleotideCounts;
end;

function TDNA.Count(aChar: Char): integer;
begin
  result := 0;
  if not fNucleotideCounts.TryGetValue(aChar, result) then
    raise EInvalidNucleotideException.Create('Invalid nucleotide in strand');
end;

end.

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.179 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.178 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.177 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.176 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.175 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.174 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.173 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.172 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.171 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.170 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.169 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.167 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.166 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.165 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.164 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.163 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.162 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.161 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.160 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas