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 Kamil0320
def checkio(n, m):
nb=list(str(bin(n)))[2:]
mb=list(str(bin(m)))[2:]
dif=len(nb)-len(mb)
if dif>=0:
mb = ["0" for i in range (dif)] + mb
else:
nb = ["0" for i in range (-dif)] + nb
res=0
for i in range(len(nb)):
if nb[i]!=mb[i]:
res+=1
return res
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. 28, 2016