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 BartoszKowalski
def checkio(n, m):
n = bin(n)
m = bin(m)
n = n[2:]
m = m[2:]
if len(m)>len(n):
n = (len(m)-len(n))*"0" + n
if len(n)>len(m):
m = (len(n)-len(m))*"0" + m
i = 0
result = 0
for a in n:
if a!=m[i]:
result = result + 1
i = i + 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(16, 15) == 5, "Third example"
Nov. 17, 2018