Sha256: a1e5fe91d13d2c62f7ce6b1b145dbaa7a869a61039e52c0f1e770021f29bf515

Contents?: true

Size: 1.6 KB

Versions: 189

Compression:

Stored size: 1.6 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');
end;

end.

Version data entries

189 entries across 189 versions & 1 rubygems

Version Path
trackler-2.1.0.8 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.7 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.6 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.5 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.4 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.3 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.2 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.1 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.1.0.0 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.55 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.54 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.53 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.52 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.51 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.50 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.49 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.48 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.47 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.46 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.0.8.45 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas