Skip to content

Commit 39b1a49

Browse files
refactor
1 parent 977fbce commit 39b1a49

File tree

1 file changed

+14
-8
lines changed
  • exercises/practice/protein-translation/.meta

1 file changed

+14
-8
lines changed

exercises/practice/protein-translation/.meta/example.fut

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,24 @@ local def contains (needle: []u8) (haystack: [][]u8): bool =
1414
in
1515
result
1616

17+
local def is_stop (codon: []u8): bool =
18+
contains codon ["UAA", "UAG", "UGA"]
19+
20+
local def translate (codon: []u8): amino_acid =
21+
if contains codon ["AUG"] then #methionine else
22+
if contains codon ["UUU", "UUC"] then #phenylalanine else
23+
if contains codon ["UUA", "UUG"] then #leucine else
24+
if contains codon ["UCU", "UCC", "UCA", "UCG"] then #serine else
25+
if contains codon ["UAU", "UAC"] then #tyrosine else
26+
if contains codon ["UGU", "UGC"] then #cysteine else
27+
assert (contains codon ["UGG"]) #tryptophan
28+
1729
def proteins (strand: []u8): []amino_acid =
1830
let (result, _) = loop (result, index) = ([], 0) while index < length strand do
1931
let index = index + 3
2032
let codon = assert (index <= length strand) strand[index - 3:index]
2133
in
22-
if contains codon ["AUG"] then (result ++ [#methionine], index) else
23-
if contains codon ["UUU", "UUC"] then (result ++ [#phenylalanine], index) else
24-
if contains codon ["UUA", "UUG"] then (result ++ [#leucine], index) else
25-
if contains codon ["UCU", "UCC", "UCA", "UCG"] then (result ++ [#serine], index) else
26-
if contains codon ["UAU", "UAC"] then (result ++ [#tyrosine], index) else
27-
if contains codon ["UGU", "UGC"] then (result ++ [#cysteine], index) else
28-
if contains codon ["UGG"] then (result ++ [#tryptophan], index) else
29-
assert (contains codon ["UAA", "UAG", "UGA"]) (result, length strand)
34+
if is_stop codon then (result, length strand) else
35+
(result ++ [translate codon], index)
3036
in
3137
result

0 commit comments

Comments
 (0)