Skip to content

Instantly share code, notes, and snippets.

@brettwise
Created April 6, 2016 00:55
Show Gist options
  • Save brettwise/46fd0f3a6a1020810d17022d445da128 to your computer and use it in GitHub Desktop.
Save brettwise/46fd0f3a6a1020810d17022d445da128 to your computer and use it in GitHub Desktop.
rosalind-dna-counter
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