17 lines
581 B
Mojo
17 lines
581 B
Mojo
# origin: Programming+ exercise count-base-proved
|
|
# status: unverified; `corpus.py verify` checks it on the pinned compiler
|
|
# probe: count_base with its claims as comments, as the matho pane states them
|
|
# expect-stdout: 3
|
|
def count_base(b: String, t: String) -> Int:
|
|
# ensures: result == |{ k in [0, |t|) : t[k] == b }|
|
|
var total: Int = 0
|
|
for i in range(t.count_codepoints()):
|
|
# invariant: total == |{ k in [0, i) : t[k] == b }|
|
|
if String(t[codepoint=i]) == b:
|
|
total += 1
|
|
return total
|
|
|
|
|
|
def main():
|
|
print(count_base("A", "GATTACA"))
|