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 mateusz.miekus
def checkio(n, m):
if n>m:
pom=n
n=m
m=pom
n=bin(n)
m=bin(m)
n=list(n)
m=list(m)
del n[0:2]
del m[0:2]
a=len(m)-len(n)
while a!=0:
n.insert(0,'0')
a=a-1
x=0
b=0
i=len(m)-1
while i>=0:
if(n[i]==m[i]):
b+=1
else:
x+=1
i-=1
print(n,m)
return x
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"
Nov. 5, 2016