Files
alexm 401084bab3
Test / gate (push) Failing after 19m0s
Initial commit
2026-11-12 22:23:54 -05:00

35 lines
977 B
Mojo

# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
from std.collections import Set
# Translate a reading frame into amino acids, stopping at the first stop codon.
def stops() -> Set[String]:
return Set[String]("TAA", "TAG", "TGA")
def translate(t: String) raises -> String:
var table = Dict[String, String]()
var protein: String
var codon: String
table["ATG"] = "M"
table["GCC"] = "A"
table["AAA"] = "K"
table["TTT"] = "F"
table["GGC"] = "G"
protein = ""
for i in range(0, t.count_codepoints() // 3 * 3, 3):
var _piece2 = String("")
for _at1 in range(i, i + 3):
_piece2 += String(t[codepoint=_at1])
codon = _piece2
if codon in stops():
break
elif codon in table:
protein = protein + table[codon]
else:
protein = protein + "X"
return protein
def main() raises:
print(translate("ATGGCCAAATAGTTT"))