RNA Transcription
RNA Transcription

RNA Transcription



You work for a bioengineering company that specializes in developing therapeutic solutions.

Your team has just been given a new project to develop a targeted therapy for a rare type of cancer.


It's all very complicated, but the basic idea is that sometimes people's bodies produce too much of a given protein. That can cause all sorts of havoc.

But if you can create a very specific molecule (called a micro-RNA), it can prevent the protein from being produced.

This technique is called RNA Interference.


Your task is determine the RNA complement of a given DNA sequence.

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:

  • G -> C
  • C -> G
  • T -> A
  • A -> U

If you want to look at how the inputs and outputs are structured, take a look at the examples in the test suite.

Notes on Rust implementation

By using private fields in structs with public new functions returning Option or Result (as here with DNA::new & RNA::new), we can guarantee that the internal representation of DNA is correct. Because every valid DNA string has a valid RNA string, we don't need to return a Result/Option from into_rna.

This explains the type signatures you will see in the tests.

The return types of both DNA::new() and RNA::new() are Result<Self, usize>, where the error type usize represents the index of the first invalid character (char index, not utf8).


HyperphysicsThe link opens in a new window or tab
Edit via GitHub The link opens in a new window or tab
Rust Exercism

Ready to start RNA Transcription?

Sign up to Exercism to learn and master Rust with 98 exercises, and real human mentoring, all for free.