Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Hamming Distance by cinekk
def checkio(n, m):
first = bin(n)[2:]
second = bin(m)[2:]
hamming = 0
if len(first) > len(second):
zeros = len(first) - len(second)
second = '0' * zeros + second
elif len(first) < len(second):
zeros = len(second) - len(first)
first = '0' * zeros + first
for x, y in zip(first, second):
if x == y:
continue
else:
hamming += 1
return hamming
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"
Oct. 26, 2016