Given a DNA strand, return its RNA complement (per RNA transcription).
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).
The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).
Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:
Execute the tests with:
$ mix test
In the test suites, all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by
commenting out the relevant
@tag :pending with a
# @tag :pending test "shouting" do assert Bob.hey("WATCH OUT!") == "Whoa, chill out!" end
Or, you can enable all the tests by commenting out the
ExUnit.configure line in the test suite.
# ExUnit.configure exclude: :pending, trace: true
If you're stuck on something, it may help to look at some of the available resources out there where answers might be found.
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
defmodule RnaTranscriptionTest do use ExUnit.Case # @tag :pending test "transcribes guanine to cytosine" do assert RnaTranscription.to_rna('G') == 'C' end @tag :pending test "transcribes cytosine to guanine" do assert RnaTranscription.to_rna('C') == 'G' end @tag :pending test "transcribes thymidine to adenine" do assert RnaTranscription.to_rna('T') == 'A' end @tag :pending test "transcribes adenine to uracil" do assert RnaTranscription.to_rna('A') == 'U' end @tag :pending test "it transcribes all dna nucleotides to rna equivalents" do assert RnaTranscription.to_rna('ACGTGGTCTTAA') == 'UGCACCAGAAUU' end end
ExUnit.start() ExUnit.configure(exclude: :pending, trace: true)
defmodule RnaTranscription do @doc """ Transcribes a character list representing DNA nucleotides to RNA ## Examples iex> RnaTranscription.to_rna('ACTG') 'UGAC' """ @spec to_rna(charlist()) :: charlist() def to_rna(dna) do dna |> Enum.map(&dna_to_rna/1) end defp dna_to_rna(?G), do: ?C defp dna_to_rna(?C), do: ?G defp dna_to_rna(?T), do: ?A defp dna_to_rna(?A), do: ?U end
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.