Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
The Hamming Distance solution in Uncategorized category for The Hamming Distance by capback250
# migrated from python 2.7
def checkio(n, m):
n = str(bin(n)).replace('b', '0')
m = str(bin(m)).replace('b', '0')
print(n, m)
if len(n) < len(m):
n = n.zfill(len(m))
if len(n) > len(m):
m = m.zfill(len(n))
return sum(1 for x, y in zip(n, m) if x != y)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(117, 17) == 3, "First example"
assert checkio(1, 2) == 2, "Second example"
assert checkio(16, 15) == 5, "Third example"
Aug. 1, 2015