Avatar of artemkorsakov

artemkorsakov's solution

to RNA Transcription in the C# Track

Published at Jan 29 2019 · 0 comments
Test suite

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:

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

Running the tests

To run the tests, run the command dotnet test from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the Skip property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using exercism submit RnaTranscription.cs

Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.


Hyperphysics http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


// This file was auto-generated based on version 1.3.0 of the canonical data.

using Xunit;

public class RnaTranscriptionTest
    public void Empty_rna_sequence()
        Assert.Equal("", RnaTranscription.ToRna(""));

    [Fact(Skip = "Remove to run test")]
    public void Rna_complement_of_cytosine_is_guanine()
        Assert.Equal("G", RnaTranscription.ToRna("C"));

    [Fact(Skip = "Remove to run test")]
    public void Rna_complement_of_guanine_is_cytosine()
        Assert.Equal("C", RnaTranscription.ToRna("G"));

    [Fact(Skip = "Remove to run test")]
    public void Rna_complement_of_thymine_is_adenine()
        Assert.Equal("A", RnaTranscription.ToRna("T"));

    [Fact(Skip = "Remove to run test")]
    public void Rna_complement_of_adenine_is_uracil()
        Assert.Equal("U", RnaTranscription.ToRna("A"));

    [Fact(Skip = "Remove to run test")]
    public void Rna_complement()
        Assert.Equal("UGCACCAGAAUU", RnaTranscription.ToRna("ACGTGGTCTTAA"));
using System;
using System.Linq;

public static class RnaTranscription
    public static string ToRna(string nucleotide)
        return nucleotide.ToUpper().ToCharArray().Aggregate("", (current, c) => current + (c == 'G' ? "C" : c == 'C' ? "G" : c == 'T' ? "A" : c == 'A' ? "U" : ""));

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

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.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?