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 wojtek96
def num(n):
tab = []
while n != '':
tab.append(int(n[0]))
n = n[1:]
tab.reverse()
return tab
def checkio(n, m):
a = num(bin(n)[2:])
b = num(bin(m)[2:])
sum = 0
if len(a) > len(b):
for i in range(len(b)):
a[i] = a[i] + b[i]
if a[i] == 2:
a[i] = 0
for k in range(len(a)):
sum = sum + a[k]
else:
for i in range(len(a)):
b[i] = b[i] + a[i]
if b[i] == 2:
b[i] = 0
for k in range(len(b)):
sum = sum + b[k]
return sum
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"
Dec. 15, 2016