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 Lukeram
def checkio(n, m):
k=bin(n)
l=bin(m)
k=k[2:len(k)]
l=l[2:len(l)]
c=0
if len(k)>len(l):
l='0'*(len(k)-len(l))+l
else:
k='0'*(len(l)-len(k))+k
print(k,l)
for i in range(len(k)):
if not k[i]==l[i]:
c+=1
print(c)
return c
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. 10, 2016