Skip to content

Commit 434ca3a

Browse files
Add six practice exercises
- protein-translation - relative-distance - resistor-color-duo - resistor-color-trio - two-bucket - wordy
1 parent 048d185 commit 434ca3a

51 files changed

Lines changed: 1903 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,22 @@
775775
],
776776
"difficulty": 2
777777
},
778+
{
779+
"slug": "resistor-color-duo",
780+
"name": "Resistor Color Duo",
781+
"uuid": "f295d49d-b580-403e-a5da-bf2664c15886",
782+
"practices": [],
783+
"prerequisites": [],
784+
"difficulty": 2
785+
},
786+
{
787+
"slug": "resistor-color-trio",
788+
"name": "Resistor Color Trio",
789+
"uuid": "5e28ca04-55ce-4c31-bac2-401ecb7c4dc7",
790+
"practices": [],
791+
"prerequisites": [],
792+
"difficulty": 2
793+
},
778794
{
779795
"slug": "rna-transcription",
780796
"name": "RNA Transcription",
@@ -1304,6 +1320,14 @@
13041320
],
13051321
"difficulty": 4
13061322
},
1323+
{
1324+
"slug": "protein-translation",
1325+
"name": "Protein Translation",
1326+
"uuid": "51e23591-ba3d-4577-8b78-384b64ba32d0",
1327+
"practices": [],
1328+
"prerequisites": [],
1329+
"difficulty": 4
1330+
},
13071331
{
13081332
"slug": "proverb",
13091333
"name": "Proverb",
@@ -1617,6 +1641,14 @@
16171641
],
16181642
"difficulty": 5
16191643
},
1644+
{
1645+
"slug": "relative-distance",
1646+
"name": "Relative Distance",
1647+
"uuid": "e94c2353-0ed5-4a11-b606-9c82d88ab74a",
1648+
"practices": [],
1649+
"prerequisites": [],
1650+
"difficulty": 5
1651+
},
16201652
{
16211653
"slug": "robot-name",
16221654
"name": "Robot Name",
@@ -1897,6 +1929,14 @@
18971929
],
18981930
"difficulty": 6
18991931
},
1932+
{
1933+
"slug": "two-bucket",
1934+
"name": "Two Bucket",
1935+
"uuid": "ec8d731a-9f3e-442d-99df-ea76296f6887",
1936+
"practices": [],
1937+
"prerequisites": [],
1938+
"difficulty": 6
1939+
},
19001940
{
19011941
"slug": "bank-account",
19021942
"name": "Bank Account",
@@ -1985,6 +2025,14 @@
19852025
],
19862026
"difficulty": 7
19872027
},
2028+
{
2029+
"slug": "wordy",
2030+
"name": "Wordy",
2031+
"uuid": "593abf4b-9ba6-4e31-8431-09f69263f3e1",
2032+
"practices": [],
2033+
"prerequisites": [],
2034+
"difficulty": 7
2035+
},
19882036
{
19892037
"slug": "zebra-puzzle",
19902038
"name": "Zebra Puzzle",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Instructions
2+
3+
Your job is to translate RNA sequences into proteins.
4+
5+
RNA strands are made up of three-nucleotide sequences called **codons**.
6+
Each codon translates to an **amino acid**.
7+
When joined together, those amino acids make a protein.
8+
9+
In the real world, there are 64 codons, which in turn correspond to 20 amino acids.
10+
However, for this exercise, you’ll only use a few of the possible 64.
11+
They are listed below:
12+
13+
| Codon | Amino Acid |
14+
| ------------------ | ------------- |
15+
| AUG | Methionine |
16+
| UUU, UUC | Phenylalanine |
17+
| UUA, UUG | Leucine |
18+
| UCU, UCC, UCA, UCG | Serine |
19+
| UAU, UAC | Tyrosine |
20+
| UGU, UGC | Cysteine |
21+
| UGG | Tryptophan |
22+
| UAA, UAG, UGA | STOP |
23+
24+
For example, the RNA string “AUGUUUUCU” has three codons: “AUG”, “UUU” and “UCU”.
25+
These map to Methionine, Phenylalanine, and Serine.
26+
27+
## “STOP” Codons
28+
29+
You’ll note from the table above that there are three **“STOP” codons**.
30+
If you encounter any of these codons, ignore the rest of the sequence — the protein is complete.
31+
32+
For example, “AUGUUUUCUUAAAUG” contains a STOP codon (“UAA”).
33+
Once we reach that point, we stop processing.
34+
We therefore only consider the part before it (i.e. “AUGUUUUCU”), not any further codons after it (i.e. “AUG”).
35+
36+
Learn more about [protein translation on Wikipedia][protein-translation].
37+
38+
[protein-translation]: https://en.wikipedia.org/wiki/Translation_(biology)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"authors": [
3+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"protein-translation/protein-translation.factor"
8+
],
9+
"test": [
10+
"protein-translation/protein-translation-tests.factor"
11+
],
12+
"example": [
13+
".meta/example.factor"
14+
]
15+
},
16+
"blurb": "Translate RNA sequences into proteins.",
17+
"source": "Tyler Long"
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
USING: arrays assocs grouping kernel locals math sequences vectors ;
2+
IN: protein-translation
3+
4+
ERROR: invalid-codon ;
5+
6+
CONSTANT: codon-table H{
7+
{ "AUG" "Methionine" }
8+
{ "UUU" "Phenylalanine" } { "UUC" "Phenylalanine" }
9+
{ "UUA" "Leucine" } { "UUG" "Leucine" }
10+
{ "UCU" "Serine" } { "UCC" "Serine" } { "UCA" "Serine" } { "UCG" "Serine" }
11+
{ "UAU" "Tyrosine" } { "UAC" "Tyrosine" }
12+
{ "UGU" "Cysteine" } { "UGC" "Cysteine" }
13+
{ "UGG" "Tryptophan" }
14+
{ "UAA" "STOP" } { "UAG" "STOP" } { "UGA" "STOP" }
15+
}
16+
17+
: codon>protein ( codon -- protein )
18+
codon-table ?at [ drop invalid-codon ] unless ;
19+
20+
:: proteins ( strand -- result )
21+
strand 3 group :> codons
22+
0 :> i!
23+
V{ } clone :> acc
24+
t :> going!
25+
[ going i codons length < and ] [
26+
i codons nth codon>protein
27+
dup "STOP" =
28+
[ drop f going! ]
29+
[ acc push i 1 + i! ] if
30+
] while
31+
acc >array ;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module ProteinTranslation
2+
3+
function gen_test_case(case)
4+
strand = case["input"]["strand"]
5+
expected = case["expected"]
6+
if expected isa AbstractDict && haskey(expected, "error")
7+
return """[ "$(strand)" proteins ] [ invalid-codon? ] must-fail-with"""
8+
end
9+
expected_str = isempty(expected) ? "{ }" : format_string_array(expected)
10+
return "{ $(expected_str) }\n[ \"$(strand)\" proteins ] unit-test"
11+
end
12+
13+
end
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
[2c44f7bf-ba20-43f7-a3bf-f2219c0c3f98]
13+
description = "Empty RNA sequence results in no proteins"
14+
15+
[96d3d44f-34a2-4db4-84cd-fff523e069be]
16+
description = "Methionine RNA sequence"
17+
18+
[1b4c56d8-d69f-44eb-be0e-7b17546143d9]
19+
description = "Phenylalanine RNA sequence 1"
20+
21+
[81b53646-bd57-4732-b2cb-6b1880e36d11]
22+
description = "Phenylalanine RNA sequence 2"
23+
24+
[42f69d4f-19d2-4d2c-a8b0-f0ae9ee1b6b4]
25+
description = "Leucine RNA sequence 1"
26+
27+
[ac5edadd-08ed-40a3-b2b9-d82bb50424c4]
28+
description = "Leucine RNA sequence 2"
29+
30+
[8bc36e22-f984-44c3-9f6b-ee5d4e73f120]
31+
description = "Serine RNA sequence 1"
32+
33+
[5c3fa5da-4268-44e5-9f4b-f016ccf90131]
34+
description = "Serine RNA sequence 2"
35+
36+
[00579891-b594-42b4-96dc-7ff8bf519606]
37+
description = "Serine RNA sequence 3"
38+
39+
[08c61c3b-fa34-4950-8c4a-133945570ef6]
40+
description = "Serine RNA sequence 4"
41+
42+
[54e1e7d8-63c0-456d-91d2-062c72f8eef5]
43+
description = "Tyrosine RNA sequence 1"
44+
45+
[47bcfba2-9d72-46ad-bbce-22f7666b7eb1]
46+
description = "Tyrosine RNA sequence 2"
47+
48+
[3a691829-fe72-43a7-8c8e-1bd083163f72]
49+
description = "Cysteine RNA sequence 1"
50+
51+
[1b6f8a26-ca2f-43b8-8262-3ee446021767]
52+
description = "Cysteine RNA sequence 2"
53+
54+
[1e91c1eb-02c0-48a0-9e35-168ad0cb5f39]
55+
description = "Tryptophan RNA sequence"
56+
57+
[e547af0b-aeab-49c7-9f13-801773a73557]
58+
description = "STOP codon RNA sequence 1"
59+
60+
[67640947-ff02-4f23-a2ef-816f8a2ba72e]
61+
description = "STOP codon RNA sequence 2"
62+
63+
[9c2ad527-ebc9-4ace-808b-2b6447cb54cb]
64+
description = "STOP codon RNA sequence 3"
65+
66+
[f4d9d8ee-00a8-47bf-a1e3-1641d4428e54]
67+
description = "Sequence of two protein codons translates into proteins"
68+
69+
[dd22eef3-b4f1-4ad6-bb0b-27093c090a9d]
70+
description = "Sequence of two different protein codons translates into proteins"
71+
72+
[d0f295df-fb70-425c-946c-ec2ec185388e]
73+
description = "Translate RNA strand into correct protein list"
74+
75+
[e30e8505-97ec-4e5f-a73e-5726a1faa1f4]
76+
description = "Translation stops if STOP codon at beginning of sequence"
77+
78+
[5358a20b-6f4c-4893-bce4-f929001710f3]
79+
description = "Translation stops if STOP codon at end of two-codon sequence"
80+
81+
[ba16703a-1a55-482f-bb07-b21eef5093a3]
82+
description = "Translation stops if STOP codon at end of three-codon sequence"
83+
84+
[4089bb5a-d5b4-4e71-b79e-b8d1f14a2911]
85+
description = "Translation stops if STOP codon in middle of three-codon sequence"
86+
87+
[2c2a2a60-401f-4a80-b977-e0715b23b93d]
88+
description = "Translation stops if STOP codon in middle of six-codon sequence"
89+
90+
[f6f92714-769f-4187-9524-e353e8a41a80]
91+
description = "Sequence of two non-STOP codons does not translate to a STOP codon"
92+
93+
[1e75ea2a-f907-4994-ae5c-118632a1cb0f]
94+
description = "Non-existing codon can't translate"
95+
include = false
96+
97+
[9eac93f3-627a-4c90-8653-6d0a0595bc6f]
98+
description = "Unknown amino acids, not part of a codon, can't translate"
99+
reimplements = "1e75ea2a-f907-4994-ae5c-118632a1cb0f"
100+
101+
[9d73899f-e68e-4291-b1e2-7bf87c00f024]
102+
description = "Incomplete RNA sequence can't translate"
103+
104+
[43945cf7-9968-402d-ab9f-b8a28750b050]
105+
description = "Incomplete RNA sequence can translate if valid until a STOP codon"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
USING: accessors command-line continuations debugger io kernel
2+
lexer namespaces sequences source-files.errors.debugger
3+
system tools.test vocabs vocabs.loader ;
4+
IN: exercism-tools
5+
6+
SYNTAX: STOP-HERE
7+
lexer get [ text>> length ] keep line<< ;
8+
9+
SYNTAX: TASK:
10+
lexer get next-line ;
11+
12+
! Label the test that follows with its description. The marker lets the
13+
! wrapper strip this line from captured output and attach it to the next
14+
! test as a name, rather than leaving it in the previous test's output.
15+
: description ( str -- )
16+
"###DESC### " write print ;
17+
18+
! Print one failure block in a stable, parser-friendly form. Bracketed by
19+
! markers so a wrapper can split the stream reliably and avoid Factor's
20+
! noisy callstack output (which is interleaved with subsequent failures).
21+
:: print-failure ( failure -- )
22+
"###FAIL_BEGIN###" print
23+
failure error-location print
24+
failure error>> [ error. ] [ 2drop ] recover
25+
"###FAIL_END###" print
26+
flush ;
27+
28+
: print-failures ( -- )
29+
test-failures get [ print-failure ] each ;
30+
31+
: run-exercism-tests ( -- )
32+
command-line get first
33+
[ require ] [ test ] bi
34+
test-failures get empty?
35+
[ 0 exit ] [ print-failures 1 exit ] if ;
36+
37+
MAIN: run-exercism-tests

0 commit comments

Comments
 (0)