Files
pplus-core/tests/snapshots/sync-mojo/count-base-proved.mojo
T
alexm 401084bab3
Test / gate (push) Failing after 19m0s
Initial commit
2026-11-12 22:23:54 -05:00

19 lines
559 B
Mojo

# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
# How many positions of T hold the base B, with its specification.
def count_base(b: String, t: String) -> Int:
# ENSURE RESULT == LENGTH({ K IN [0, LENGTH(T)) : T[K] == B })
var n: Int
var total: Int
n = t.count_codepoints()
total = 0
# INVARIANT Total == LENGTH({ K IN [0, I) : T[K] == B })
for i in range(n):
if String(t[codepoint=i]) == b:
total = total + 1
return total
def main():
print(count_base("A", "GATTACA"))