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 MartynaDziubalka
def checkio(n, m):
list_n = []
list_m = []
result = 0
while n != 0:
list_n.append(n%2)
n //= 2
while m != 0:
list_m.append(m%2)
m //= 2
a = len(list_n)
b = len(list_m)
if a > b:
for x in range(b - 1, a - 1):
list_m.append(0)
else:
for x in range(a, b):
list_n.append(0)
for i in range(0, len(list_n)):
if list_n[i] != list_m[i]:
result += 1
return result
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(15, 16) == 5, "Third example"
Jan. 29, 2016