Last active
March 31, 2016 20:54
-
-
Save colinrymer/7573eed08c25760bd611 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
defmodule DNA do | |
@doc ~S""" | |
Count the respective number of times that the symbols 'A', 'C', 'G', and 'T' in a given string. | |
Returns the count as four integers separated by spaces, representing occureneces of "A", "C", "G", and "T" respectively. | |
## Examples | |
iex> DNA.count("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC") | |
"20 12 17 21" | |
""" | |
@spec count(string :: String.t) :: String.t | |
def count(string), do: _count(string, [0,0,0,0]) | |
def _count("", [a,c,g,t]), do: "#{a} #{c} #{g} #{t}" | |
def _count("A" <> rest, [a,c,g,t]), do: _count(rest, [a+1,c,g,t]) | |
def _count("C" <> rest, [a,c,g,t]), do: _count(rest, [a,c+1,g,t]) | |
def _count("G" <> rest, [a,c,g,t]), do: _count(rest, [a,c,g+1,t]) | |
def _count("T" <> rest, [a,c,g,t]), do: _count(rest, [a,c,g,t+1]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment