Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Hamming Distance by mdroz
def checkio(n, m):
n = format(n, '08b')
m = format(m, '08b')
helper = 0
xor=0
if len(n) > len(m):
helper = n
n = m
m = helper
i = len(m)
for signs in n[::-1]:
if(signs != m[i-1]):
xor+=1
i-=1
print(xor)
if len(n) > len(m):
n = n[ 0 : len(n)-len(m)]
xor+=n.count('1')
elif len(n) < len(m):
m= m[ 0 : len(m)-len(n)]
xor+=m.count('1')
return xor
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(1, 999999) == 3, "First example"
assert checkio(1, 2) == 2, "Second example"
assert checkio(16, 15) == 5, "Third example"
Nov. 14, 2017