18 lines
633 B
Mojo
18 lines
633 B
Mojo
# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
|
|
|
|
# How many positions differ between two reads of the same length.
|
|
def hamming(a: String, b: String) -> Int:
|
|
# REQUIRE LENGTH(A) == LENGTH(B)
|
|
# ENSURE RESULT == LENGTH({ K IN [0, LENGTH(A)) : A[K] != B[K] })
|
|
var differences: Int
|
|
differences = 0
|
|
# INVARIANT Differences == LENGTH({ K IN [0, I) : A[K] != B[K] })
|
|
for i in range(a.count_codepoints()):
|
|
if String(a[codepoint=i]) != String(b[codepoint=i]):
|
|
differences = differences + 1
|
|
return differences
|
|
|
|
|
|
def main():
|
|
print(hamming("GATTACA", "GACTATA"))
|