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 Razzerrer
def checkio(n, m):
n,m="0"*(max(len(bin(n)[2:]),len(bin(m)[2:]))-len(bin(n)[2:]))+bin(n)[2:],"0"*(max(len(bin(n)[2:]),len(bin(m)[2:]))-len(bin(m)[2:]))+bin(m)[2:]
dif=0
for i in range(len(n)):
if int(n[i])-int(m[i])!=0: dif+=1
return dif
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. 29, 2016