Files
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

22 lines
718 B
Mojo

# origin: Programming+ exercise kmers
# status: unverified; `corpus.py verify` checks it on the pinned compiler
# probe: how many times each word of k letters occurs in t
# expect-stdout: {GAT: 2, ATT: 2, TTA: 1, TAC: 1, ACA: 1, CAG: 1, AGA: 1}
def kmer_counts(t: String, k: Int) raises -> Dict[String, Int]:
# requires: k >= 1
var counts = Dict[String, Int]()
var n = t.count_codepoints()
for i in range(n - k + 1):
var word = String("")
for j in range(k):
word += String(t[codepoint=i + j])
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return counts^
def main() raises:
print(kmer_counts("GATTACAGATT", 3))