Created
September 16, 2015 21:36
-
-
Save workmad3/a092218b1983bd497729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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