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.2.1.46 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.45 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.44 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.43 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.42 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.41 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.40 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.39 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.38 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.37 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.36 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.35 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.34 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.33 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.32 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.31 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.30 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.29 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.28 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas
trackler-2.2.1.27 tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas