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 jtarnowska
def checkio(n, m):
nbin = bin(n)
print(nbin)
mbin = bin(m)
print(mbin)
listn = []
listm = []
for n in nbin:
if n == "0" or n == "1":
listn.append(n)
for m in mbin:
if m == "0" or m == "1":
listm.append(m)
a = 0
if len(listn) > len(listm):
for m in range((len(listn))-(len(listm))):
listm = [a] + listm
else:
for n in range((len(listm))-(len(listn))):
listn = [a] + listn
listn = [int(i) for i in listn]
listm = [int(i) for i in listm]
count = 0
for i in range (len(listn)):
if listn[i] != listm[i]:
count += 1
return count
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"
Jan. 17, 2017