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 hypehr96
def checkio(n, m):
nB = bin(n)[2:]
mB = bin(m)[2:]
lenNB = len(nB)
lenMB = len(mB)
roznica = lenNB-lenMB
appe = ""
if(roznica>0):
for i in range(roznica):
appe+="0"
mB=appe+mB
if (roznica<0):
roznica*=-1;
for i in range(roznica):
appe+="0"
nB=appe+nB
ilsoc = 0
key = 0
for i in nB:
if nB[key]!= mB[key]:
ilsoc+=1
key+=1
return ilsoc
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. 21, 2016