Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dark magic solution in Creative category for Multiplication Table by CDG.Axel
def checkio(first, second):
# dark magic single line
return sum((1 << second.bit_length()) - 1 if e == '1' else second for e in f'{first:b}') << 1
# alternative solution - dark bit magic
total, mask = 0, (1 << second.bit_length()) - 1
while first:
total += (mask if first & 1 else second)
first >>= 1
return total << 1
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(4, 6) == 38
assert checkio(2, 7) == 28
assert checkio(7, 2) == 18
Oct. 16, 2021
Comments: