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 Angelika
def bin(n):
x=""
while(n>0):
if n%2==1:
x='1'+x
else:
x='0'+x
n=n//2
return x
def checkio(n, m):
x=""
y=""
ile=0
x=bin(n)
y=bin(m)
a=len(x)
b=len(y)
for i in range(a-b):
y='0'+y
for i in range(b-a):
x='0'+x
for i in range(len(x)):
if((x[i:i+1]=='0' and y[i:i+1]=='1') or (x[i:i+1]=='1' and y[i:i+1]=='0')):
ile=ile+1
return ile
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