# 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"))