Skip to content

Commit c2b3e04

Browse files
authored
Exercise RNA Transcription from PR #37 (author gvrooyen) (#146)
The 11 exercises in PR #37 have been stuck in limbo since last year. They were mostly complete except for the description tags and some minor changes to match the track convention. This PR just includes the update work.
1 parent b3a2920 commit c2b3e04

File tree

8 files changed

+205
-0
lines changed

8 files changed

+205
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@
278278
"prerequisites": [],
279279
"difficulty": 2
280280
},
281+
{
282+
"slug": "rna-transcription",
283+
"name": "RNA Transcription",
284+
"uuid": "6f0407a2-2050-47cf-969e-769728fed0d0",
285+
"practices": [],
286+
"prerequisites": [],
287+
"difficulty": 2
288+
},
281289
{
282290
"slug": "robot-name",
283291
"name": "Robot Name",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Instructions
2+
3+
Your task is to determine the RNA complement of a given DNA sequence.
4+
5+
Both DNA and RNA strands are a sequence of nucleotides.
6+
7+
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), guanine (**G**), and thymine (**T**).
8+
9+
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), guanine (**G**), and uracil (**U**).
10+
11+
Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:
12+
13+
- `G` -> `C`
14+
- `C` -> `G`
15+
- `T` -> `A`
16+
- `A` -> `U`
17+
18+
~~~~exercism/note
19+
If you want to look at how the inputs and outputs are structured, take a look at the examples in the test suite.
20+
~~~~
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Introduction
2+
3+
You work for a bioengineering company that specializes in developing therapeutic solutions.
4+
5+
Your team has just been given a new project to develop a targeted therapy for a rare type of cancer.
6+
7+
~~~~exercism/note
8+
It's all very complicated, but the basic idea is that sometimes people's bodies produce too much of a given protein.
9+
That can cause all sorts of havoc.
10+
11+
But if you can create a very specific molecule (called a micro-RNA), it can prevent the protein from being produced.
12+
13+
This technique is called [RNA Interference][rnai].
14+
15+
[rnai]: https://admin.acceleratingscience.com/ask-a-scientist/what-is-rnai/
16+
~~~~
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"authors": [
3+
"gvrooyen"
4+
],
5+
"contributors": [
6+
"rmonnet"
7+
],
8+
"files": {
9+
"solution": [
10+
"rna_transcription.odin"
11+
],
12+
"test": [
13+
"rna_transcription_test.odin"
14+
],
15+
"example": [
16+
".meta/example.odin"
17+
]
18+
},
19+
"blurb": "Given a DNA strand, return its RNA complement.",
20+
"source": "Hyperphysics",
21+
"source_url": "https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html"
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package rna_transcription
2+
3+
to_rna :: proc(dna: string) -> (rna: string, ok: bool) {
4+
5+
rna_strand := make([]byte, len(dna))
6+
7+
for x, i in dna {
8+
switch x {
9+
case 'G':
10+
rna_strand[i] = 'C'
11+
case 'C':
12+
rna_strand[i] = 'G'
13+
case 'T':
14+
rna_strand[i] = 'A'
15+
case 'A':
16+
rna_strand[i] = 'U'
17+
case:
18+
return
19+
}
20+
}
21+
rna = string(rna_strand)
22+
ok = true
23+
return
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[b4631f82-c98c-4a2f-90b3-c5c2b6c6f661]
13+
description = "Empty RNA sequence"
14+
15+
[a9558a3c-318c-4240-9256-5d5ed47005a6]
16+
description = "RNA complement of cytosine is guanine"
17+
18+
[6eedbb5c-12cb-4c8b-9f51-f8320b4dc2e7]
19+
description = "RNA complement of guanine is cytosine"
20+
21+
[870bd3ec-8487-471d-8d9a-a25046488d3e]
22+
description = "RNA complement of thymine is adenine"
23+
24+
[aade8964-02e1-4073-872f-42d3ffd74c5f]
25+
description = "RNA complement of adenine is uracil"
26+
27+
[79ed2757-f018-4f47-a1d7-34a559392dbf]
28+
description = "RNA complement"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package rna_transcription
2+
3+
to_rna :: proc(dna: string) -> (rna: string, ok: bool) {
4+
// Implement the procedure.
5+
return "", false
6+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package rna_transcription
2+
3+
import "core:mem"
4+
import "core:testing"
5+
6+
@(test)
7+
/// description = Empty RNA sequence
8+
test_empty_rna_sequence :: proc(t: ^testing.T) {
9+
rna, ok := to_rna("")
10+
defer delete(rna)
11+
12+
testing.expect_value(t, rna, "")
13+
testing.expect(t, ok)
14+
}
15+
16+
@(test)
17+
/// description = RNA complement of cytosine is guanine
18+
test_rna_complement_of_cytosine_is_guanine :: proc(t: ^testing.T) {
19+
rna, ok := to_rna("C")
20+
defer delete(rna)
21+
22+
testing.expect_value(t, rna, "G")
23+
testing.expect(t, ok)
24+
}
25+
26+
@(test)
27+
/// description = RNA complement of guanine is cytosine
28+
test_rna_complement_of_guanine_is_cytosine :: proc(t: ^testing.T) {
29+
rna, ok := to_rna("G")
30+
defer delete(rna)
31+
32+
testing.expect_value(t, rna, "C")
33+
testing.expect(t, ok)
34+
}
35+
36+
@(test)
37+
/// description = RNA complement of thymine is adenine
38+
test_rna_complement_of_thymine_is_adenine :: proc(t: ^testing.T) {
39+
rna, ok := to_rna("T")
40+
defer delete(rna)
41+
42+
testing.expect_value(t, rna, "A")
43+
testing.expect(t, ok)
44+
}
45+
46+
@(test)
47+
/// description = RNA complement of adenine is uracil
48+
test_rna_complement_of_adenine_is_uracil :: proc(t: ^testing.T) {
49+
rna, ok := to_rna("A")
50+
defer delete(rna)
51+
52+
testing.expect_value(t, rna, "U")
53+
testing.expect(t, ok)
54+
}
55+
56+
@(test)
57+
/// description = RNA complement
58+
test_rna_complement :: proc(t: ^testing.T) {
59+
rna, ok := to_rna("ACGTGGTCTTAA")
60+
defer delete(rna)
61+
62+
testing.expect_value(t, rna, "UGCACCAGAAUU")
63+
testing.expect(t, ok)
64+
}
65+
66+
// This test is optional.
67+
// If you want to know if your solution has any memory leak,
68+
// then un-comment the test attribute below.
69+
// If you want to learn more about Odin's tracking allocation,
70+
// you can watch this You Tube video
71+
// https://www.youtube.com/watch?v=dg6qogN8kIE
72+
// @(test)
73+
test_no_memory_leaks :: proc(t: ^testing.T) {
74+
track: mem.Tracking_Allocator
75+
mem.tracking_allocator_init(&track, context.allocator)
76+
defer mem.tracking_allocator_destroy(&track)
77+
context.allocator = mem.tracking_allocator(&track)
78+
test_rna_complement(t)
79+
testing.expect_value(t, len(track.allocation_map), 0)
80+
testing.expect_value(t, len(track.bad_free_array), 0)
81+
}

0 commit comments

Comments
 (0)