Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
zip is an interesting function solution in Creative category for The Hamming Distance by Dragonfly555
def checkio(n, m):
binn = str(bin(n))[2:]
binm = str(bin(m))[2:]
if len(binn) > len(binm): binm = binm.zfill(len(binn))
else: binn = binn.zfill(len(binm))
return sum(ch1 != ch2 for ch1, ch2 in zip(binn, binm))
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"
Aug. 24, 2015