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 wolicki.mikolaj
# migrated from python 2.7
def checkio(n, m):
if m>n:
a=bin(m)[2:]
d=len(a)
b=bin(n)[2:].zfill(d)
else:
a=bin(n)[2:]
d=len(a)
b=bin(m)[2:].zfill(d)
wynik=""
for i in range(len(a)):
if a[i]=="0" and b[i]=="0":
wynik=wynik+"0"
else:
if a[i]=="1" and b[i]=="1":
wynik=wynik+"0"
else:
print(a[i],b[i],"qqqq")
wynik=wynik+"1"
return wynik.count("1")
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. 14, 2016