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 Mahoter
def checkio(n, m):
bitn = []
bitm = []
while n > 0:
if n%2 == 1:
bitn += [1]
n = n-1
n = n/2
else:
bitn += [0]
n = n/2
while m > 0:
if m%2 == 1:
bitm += [1]
m = m-1
m = m/2
else:
bitm += [0]
m = m/2
if len(bitn) > len(bitm):
while len(bitn) > len(bitm):
bitm += [0]
elif len(bitn) < len(bitm):
while len(bitn) < len(bitm):
bitn += [0]
bitn.reverse()
bitm.reverse()
a = 0
res = 0
while a < len(bitn):
if bitn[a] != bitm[a]:
res += 1
a += 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"
Jan. 17, 2016