Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simplest solution in Clear category for Multiplication Table by cs1g
def checkio(first, second):
first, N = bin(first)[2:], len(bin(second)[2:])
sum_AND = sum(int(bit * N, 2) & second for bit in first)
sum_OR = sum(int(bit * N, 2) | second for bit in first)
sum_XOR = sum(int(bit * N, 2) ^ second for bit in first)
return sum_AND + sum_OR + sum_XOR
#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
July 13, 2017