add hello world properly, add rna-transcription (elixir is neat!)

This commit is contained in:
Xevion
2021-01-18 01:15:35 -06:00
parent 0c18055cd3
commit 4c28e4d439
14 changed files with 239 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
defmodule RnaTranscription do
# Turns all 1-item charlist keys and values inside the base map into integers
@transcription %{'G' => 'C', 'C' => 'G', 'T' => 'A', 'A' => 'U'} |> Enum.map(fn ({k, v}) -> {List.first(k), List.first(v)} end) |> Enum.into(%{})
@doc """
Transcribes a character list representing DNA nucleotides to RNA
## Examples
iex> RnaTranscription.to_rna('ACTG')
'UGAC'
"""
@spec to_rna([char]) :: [char]
def to_rna(dna) do
dna |> Enum.map(fn (x) -> Map.get(@transcription, x) end)
end
end