18 lines
546 B
Mojo
18 lines
546 B
Mojo
# origin: Programming+ exercise tally
|
|
# status: unverified; `corpus.py verify` checks it on the pinned compiler
|
|
# probe: how many times each base appears in t, in a Dict
|
|
# expect-stdout: {G: 1, A: 3, T: 2, C: 1}
|
|
def tally_bases(t: String) raises -> Dict[String, Int]:
|
|
var tally = Dict[String, Int]()
|
|
for i in range(t.count_codepoints()):
|
|
var b = String(t[codepoint=i])
|
|
if b in tally:
|
|
tally[b] += 1
|
|
else:
|
|
tally[b] = 1
|
|
return tally^
|
|
|
|
|
|
def main() raises:
|
|
print(tally_bases("GATTACA"))
|