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 Bartek.Knobel
def checkio(n, m):
a = str(bin(n).lstrip("0b"))
b = str(bin(m).lstrip("0b"))
if(m>n):
a = a.zfill(len(b))
else:
b = b.zfill(len(a))
d=0
for i in range(len(a)):
if a[i]!=b[i]:
d+=1
return d
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"
Dec. 12, 2016