This commit is contained in:
commit
568474d52f
1591 files changed
+528213
No files matched your search
@@ -0,0 +1,26 @@
|
||||
# origin: Programming+ exercise translate-codons
|
||||
# status: unverified; `corpus.py verify` checks it on the pinned compiler
|
||||
# probe: translate a reading frame into amino acids, stopping at the first stop codon
|
||||
# expect-stdout: MAK
|
||||
def translate(t: String) raises -> String:
|
||||
var stops = ["TAA", "TAG", "TGA"]
|
||||
var table = {"ATG": "M", "GCC": "A", "AAA": "K", "TTT": "F", "GGC": "G"}
|
||||
var protein = String("")
|
||||
var n = t.count_codepoints()
|
||||
var i = 0
|
||||
while i + 3 <= n:
|
||||
var codon = String("")
|
||||
for j in range(3):
|
||||
codon += String(t[codepoint=i + j])
|
||||
if codon in stops:
|
||||
break
|
||||
elif codon in table:
|
||||
protein += table[codon]
|
||||
else:
|
||||
protein += "X"
|
||||
i += 3
|
||||
return protein^
|
||||
|
||||
|
||||
def main() raises:
|
||||
print(translate("ATGGCCAAATAGTTT"))
|
||||
Reference in new issue
Block a user