Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created September 16, 2015 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmad3/a092218b1983bd497729 to your computer and use it in GitHub Desktop.
Save workmad3/a092218b1983bd497729 to your computer and use it in GitHub Desktop.
-module(dna).
-export([count/2, nucleotide_counts/1]).
nucleotides()-> ["A", "T", "C", "G"].
count(Strand, TargetNucleotide)->
case lists:member(TargetNucleotide, nucleotides()) of
true ->
erlang:length(
lists:filter(
fun(CandidateNucleotide)-> [CandidateNucleotide] == TargetNucleotide end,
Strand
)
);
false -> erlang:error("Invalid nucleotide")
end.
nucleotide_counts(Strand)->
lists:map(
fun(Nucleotide)-> {Nucleotide, count(Strand, Nucleotide)} end,
nucleotides()
).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment