@@ -0,0 +1,43 @@ | |||
# RNA Transcription | |||
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` | |||
## Hints | |||
For this exercise the following F# feature comes in handy: | |||
- [Match Expressions](https://fsharpforfunandprofit.com/posts/match-expression/) While this can be solved using a dictionary, using a match expression is more idiomatic. | |||
## Running the tests | |||
To run the tests, run the command `dotnet test` from within the exercise directory. | |||
## Autoformatting the code | |||
F# source code can be formatted with the [Fantomas](https://github.com/fsprojects/fantomas) tool. | |||
After installing it with `dotnet tool restore`, run `dotnet fantomas .` to format code within the current directory. | |||
## Further information | |||
For more detailed information about the F# track, including how to get help if | |||
you're having trouble, please visit the exercism.io [F# language page](http://exercism.io/languages/fsharp/resources). | |||
## Source | |||
Hyperphysics [http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html](http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html) | |||
@@ -0,0 +1,11 @@ | |||
module RnaTranscription | |||
let toRna (dna: string): string = | |||
dna | |||
|> String.map (fun x -> | |||
match x with | |||
| 'G' -> 'C' | |||
| 'C' -> 'G' | |||
| 'T' -> 'A' | |||
| 'A' -> 'U' | |||
| _ -> ' ') |
@@ -0,0 +1,21 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>netcoreapp3.0</TargetFramework> | |||
<IsPackable>false</IsPackable> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Compile Include="RnaTranscription.fs" /> | |||
<Compile Include="RnaTranscriptionTests.fs" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> | |||
<PackageReference Include="xunit" Version="2.4.1" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> | |||
<PackageReference Include="FsUnit.xUnit" Version="3.8.1" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,33 @@ | |||
// This file was auto-generated based on version 1.3.0 of the canonical data. | |||
module RnaTranscriptionTests | |||
open FsUnit.Xunit | |||
open Xunit | |||
open RnaTranscription | |||
[<Fact>] | |||
let ``Empty RNA sequence`` () = | |||
toRna "" |> should equal "" | |||
[<Fact>] | |||
let ``RNA complement of cytosine is guanine`` () = | |||
toRna "C" |> should equal "G" | |||
[<Fact>] | |||
let ``RNA complement of guanine is cytosine`` () = | |||
toRna "G" |> should equal "C" | |||
[<Fact>] | |||
let ``RNA complement of thymine is adenine`` () = | |||
toRna "T" |> should equal "A" | |||
[<Fact>] | |||
let ``RNA complement of adenine is uracil`` () = | |||
toRna "A" |> should equal "U" | |||
[<Fact>] | |||
let ``RNA complement`` () = | |||
toRna "ACGTGGTCTTAA" |> should equal "UGCACCAGAAUU" | |||