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

18 lines
621 B
Mojo

# origin: Programming+ exercise hamming
# status: unverified; `corpus.py verify` checks it on the pinned compiler
# probe: how many positions differ between two reads of the same length
# expect-stdout: 2
def hamming(a: String, b: String) -> Int:
# requires: |a| == |b|
# ensures: result == |{ k in [0, |a|) : a[k] != b[k] }|
var differences = 0
for i in range(a.count_codepoints()):
# invariant: differences == |{ k in [0, i) : a[k] != b[k] }|
if a[codepoint=i] != b[codepoint=i]:
differences += 1
return differences
def main():
print(hamming("GATTACA", "GACTATA"))