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:
For installation and learning resources, refer to the exercism help page.
To work on the exercises, you will need
Base. Consult opam website for instructions on how to install
opam for your OS. Once
opam is installed open a terminal window and run the following command to install base:
opam install base
To run the tests you will need
OUnit. Install it using
opam install ounit
A Makefile is provided with a default target to compile your solution and run the tests. At the command line, type:
utop is a command line program which allows you to run Ocaml code interactively. The easiest way to install it is via opam:
opam install utop
Consult utop for more detail.
The exercism/ocaml repository on GitHub is the home for all of the Ocaml exercises.
If you have feedback about an exercise, or want to help implementing a new one, head over there and create an issue. We'll do our best to help you!
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
open Base open OUnit2 let char_of_variant = function | `A -> 'A' | `C -> 'C' | `G -> 'G' | `T -> 'T' | `U -> 'U' let printer l = List.map ~f:char_of_variant l |> String.of_char_list let ae exp got _test_ctxt = assert_equal ~printer exp got let tests = ["transcribes empty list">:: ae  (Rna_transcription.to_rna ); "transcribes cytidine">:: ae [`G] (Rna_transcription.to_rna [`C]); "transcribes guanosine">:: ae [`C] (Rna_transcription.to_rna [`G]); "transcribes adenosie">:: ae [`U] (Rna_transcription.to_rna [`A]); "transcribes thymidine">:: ae [`A] (Rna_transcription.to_rna [`T]); "transcribes multiple">:: ae [`U; `G; `C; `A; `C; `C; `A; `G; `A; `A; `U; `U] (Rna_transcription.to_rna [`A; `C; `G; `T; `G; `G; `T; `C; `T; `T; `A; `A]) ] let () = run_test_tt_main ("rna-transcription tests" >::: tests)
open Core type dna = [ `A | `C | `G | `T ] type rna = [ `A | `C | `G | `U ] let to_rna (dl : dna list) = List.map dl ~f:(function | `G -> `C | `C -> `G | `T -> `A | `A -> `U )
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.