diff --git a/config.json b/config.json index 3c881e8..fc20daf 100644 --- a/config.json +++ b/config.json @@ -278,6 +278,14 @@ "prerequisites": [], "difficulty": 2 }, + { + "slug": "rna-transcription", + "name": "RNA Transcription", + "uuid": "6f0407a2-2050-47cf-969e-769728fed0d0", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "robot-name", "name": "Robot Name", diff --git a/exercises/practice/rna-transcription/.docs/instructions.md b/exercises/practice/rna-transcription/.docs/instructions.md new file mode 100644 index 0000000..4dbfd3a --- /dev/null +++ b/exercises/practice/rna-transcription/.docs/instructions.md @@ -0,0 +1,20 @@ +# Instructions + +Your task is to 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` + +~~~~exercism/note +If you want to look at how the inputs and outputs are structured, take a look at the examples in the test suite. +~~~~ diff --git a/exercises/practice/rna-transcription/.docs/introduction.md b/exercises/practice/rna-transcription/.docs/introduction.md new file mode 100644 index 0000000..6b3f44b --- /dev/null +++ b/exercises/practice/rna-transcription/.docs/introduction.md @@ -0,0 +1,16 @@ +# Introduction + +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. + +~~~~exercism/note +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][rnai]. + +[rnai]: https://admin.acceleratingscience.com/ask-a-scientist/what-is-rnai/ +~~~~ diff --git a/exercises/practice/rna-transcription/.meta/config.json b/exercises/practice/rna-transcription/.meta/config.json new file mode 100644 index 0000000..7b0ffd4 --- /dev/null +++ b/exercises/practice/rna-transcription/.meta/config.json @@ -0,0 +1,22 @@ +{ + "authors": [ + "gvrooyen" + ], + "contributors": [ + "rmonnet" + ], + "files": { + "solution": [ + "rna_transcription.odin" + ], + "test": [ + "rna_transcription_test.odin" + ], + "example": [ + ".meta/example.odin" + ] + }, + "blurb": "Given a DNA strand, return its RNA complement.", + "source": "Hyperphysics", + "source_url": "https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html" +} diff --git a/exercises/practice/rna-transcription/.meta/example.odin b/exercises/practice/rna-transcription/.meta/example.odin new file mode 100644 index 0000000..4d940ae --- /dev/null +++ b/exercises/practice/rna-transcription/.meta/example.odin @@ -0,0 +1,24 @@ +package rna_transcription + +to_rna :: proc(dna: string) -> (rna: string, ok: bool) { + + rna_strand := make([]byte, len(dna)) + + for x, i in dna { + switch x { + case 'G': + rna_strand[i] = 'C' + case 'C': + rna_strand[i] = 'G' + case 'T': + rna_strand[i] = 'A' + case 'A': + rna_strand[i] = 'U' + case: + return + } + } + rna = string(rna_strand) + ok = true + return +} diff --git a/exercises/practice/rna-transcription/.meta/tests.toml b/exercises/practice/rna-transcription/.meta/tests.toml new file mode 100644 index 0000000..6800514 --- /dev/null +++ b/exercises/practice/rna-transcription/.meta/tests.toml @@ -0,0 +1,28 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[b4631f82-c98c-4a2f-90b3-c5c2b6c6f661] +description = "Empty RNA sequence" + +[a9558a3c-318c-4240-9256-5d5ed47005a6] +description = "RNA complement of cytosine is guanine" + +[6eedbb5c-12cb-4c8b-9f51-f8320b4dc2e7] +description = "RNA complement of guanine is cytosine" + +[870bd3ec-8487-471d-8d9a-a25046488d3e] +description = "RNA complement of thymine is adenine" + +[aade8964-02e1-4073-872f-42d3ffd74c5f] +description = "RNA complement of adenine is uracil" + +[79ed2757-f018-4f47-a1d7-34a559392dbf] +description = "RNA complement" diff --git a/exercises/practice/rna-transcription/rna_transcription.odin b/exercises/practice/rna-transcription/rna_transcription.odin new file mode 100644 index 0000000..6c8a69f --- /dev/null +++ b/exercises/practice/rna-transcription/rna_transcription.odin @@ -0,0 +1,6 @@ +package rna_transcription + +to_rna :: proc(dna: string) -> (rna: string, ok: bool) { + // Implement the procedure. + return "", false +} diff --git a/exercises/practice/rna-transcription/rna_transcription_test.odin b/exercises/practice/rna-transcription/rna_transcription_test.odin new file mode 100644 index 0000000..9578e41 --- /dev/null +++ b/exercises/practice/rna-transcription/rna_transcription_test.odin @@ -0,0 +1,81 @@ +package rna_transcription + +import "core:mem" +import "core:testing" + +@(test) +/// description = Empty RNA sequence +test_empty_rna_sequence :: proc(t: ^testing.T) { + rna, ok := to_rna("") + defer delete(rna) + + testing.expect_value(t, rna, "") + testing.expect(t, ok) +} + +@(test) +/// description = RNA complement of cytosine is guanine +test_rna_complement_of_cytosine_is_guanine :: proc(t: ^testing.T) { + rna, ok := to_rna("C") + defer delete(rna) + + testing.expect_value(t, rna, "G") + testing.expect(t, ok) +} + +@(test) +/// description = RNA complement of guanine is cytosine +test_rna_complement_of_guanine_is_cytosine :: proc(t: ^testing.T) { + rna, ok := to_rna("G") + defer delete(rna) + + testing.expect_value(t, rna, "C") + testing.expect(t, ok) +} + +@(test) +/// description = RNA complement of thymine is adenine +test_rna_complement_of_thymine_is_adenine :: proc(t: ^testing.T) { + rna, ok := to_rna("T") + defer delete(rna) + + testing.expect_value(t, rna, "A") + testing.expect(t, ok) +} + +@(test) +/// description = RNA complement of adenine is uracil +test_rna_complement_of_adenine_is_uracil :: proc(t: ^testing.T) { + rna, ok := to_rna("A") + defer delete(rna) + + testing.expect_value(t, rna, "U") + testing.expect(t, ok) +} + +@(test) +/// description = RNA complement +test_rna_complement :: proc(t: ^testing.T) { + rna, ok := to_rna("ACGTGGTCTTAA") + defer delete(rna) + + testing.expect_value(t, rna, "UGCACCAGAAUU") + testing.expect(t, ok) +} + +// This test is optional. +// If you want to know if your solution has any memory leak, +// then un-comment the test attribute below. +// If you want to learn more about Odin's tracking allocation, +// you can watch this You Tube video +// https://www.youtube.com/watch?v=dg6qogN8kIE +// @(test) +test_no_memory_leaks :: proc(t: ^testing.T) { + track: mem.Tracking_Allocator + mem.tracking_allocator_init(&track, context.allocator) + defer mem.tracking_allocator_destroy(&track) + context.allocator = mem.tracking_allocator(&track) + test_rna_complement(t) + testing.expect_value(t, len(track.allocation_map), 0) + testing.expect_value(t, len(track.bad_free_array), 0) +}