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 u2ezi
def checkio(a, b):
a=bin(a)[2:]
b=bin(b)[2:]
if len(b)>len(a):
tmp=b
b=a
a=tmp
res=0
for i in range(len(a)-len(b)):
b='0'+b
for i in range(len(b)):
if b[i]!=a[i]: res+=1
return res
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. 31, 2016