Skip to content

Instantly share code, notes, and snippets.

@zph
Created May 9, 2020 18:10
Show Gist options
  • Save zph/f9cd6f7538a3c80a64944eb40d7be5ee to your computer and use it in GitHub Desktop.
Save zph/f9cd6f7538a3c80a64944eb40d7be5ee to your computer and use it in GitHub Desktop.
defmodule RnaTranscription do
@doc """
Transcribes a character list representing DNA nucleotides to RNA
## Examples
RnaTranscription.to_rna('ACTG')
'UGAC'
"""
@rna_map %{?A => 'U', ?T => 'A', ?G => 'C', ?C => 'G'}
def lookup(k) do
@rna_map[k]
end
@spec to_rna([char]) :: [char]
def to_rna(dna) do
dna
|> Enum.map(&lookup(&1))
|> Enum.reduce(&(&2 ++ &1))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment