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