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 voxes96
def checkio(n, m):
an = ""
am = ""
h = 0
if(n>m):
while(n>0):
an = str(n%2) + an
n = n // 2
for i in range(len(an)):
am = str(m%2) + am
m = m // 2
else:
while(m>0):
am = str(m%2) + am
m = m // 2
for i in range(len(am)):
an = str(n%2) + an
n = n // 2
for i in range(len(an)):
if(an[i] != am[i]):
h = h + 1
return h
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. 29, 2016