Created
April 6, 2016 00:55
-
-
Save brettwise/46fd0f3a6a1020810d17022d445da128 to your computer and use it in GitHub Desktop.
rosalind-dna-counter
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 DnaCounter do | |
def main(string) do | |
dna_list = | |
string | |
|> String.codepoints | |
letters_to_count = get_letters_to_count(dna_list) | |
count_occurences(dna_list, letters_to_count) | |
end | |
def get_letters_to_count(dna_list) do | |
dna_list | |
|> Enum.sort | |
|> Enum.dedup | |
end | |
def count_occurences(_, []) do | |
IO.puts "Finished" | |
end | |
def count_occurences(dna_list, letters_to_count) do | |
[head | tail] = letters_to_count | |
IO.puts Enum.count(dna_list, fn(x) -> x == head end) | |
count_occurences(dna_list, tail) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment