Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Multiplication Table by Kurush
def checkio(first, second):
bits_first = bin(first)[2:]
bits_second = bin(second)[2:]
stephan_mult = 0
for bit_first in bits_first:
and_row = []
or_row = []
xor_row = []
for bit_second in bits_second:
and_row.append(str(int(bit_first) and int(bit_second)))
or_row.append(str(int(bit_first) or int(bit_second)))
xor_row.append(str(int(bit_first) ^ int(bit_second)))
stephan_mult += int("".join(and_row), 2) + int("".join(or_row), 2) + int("".join(xor_row), 2)
return stephan_mult
#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
June 27, 2014