This commit is contained in:
commit
568474d52f
1591 files changed
+528213
No files matched your search
@@ -0,0 +1,21 @@
|
||||
# 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))
|
||||
Reference in new issue
Block a user