Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Multiplication Table by dig
def checkio(n1: int, n2: int) -> int:
bin_n1, bin_n2 = bin(n1)[2:], bin(n2)[2:]
and_sum, or_sum, xor_sum = 0, 0, 0
for row_digit in bin_n1:
and_row, or_row, xor_row = '', '', ''
for col_digit in bin_n2:
and_row += str(int(row_digit) & int(col_digit))
or_row += str(int(row_digit) | int(col_digit))
xor_row += str(int(row_digit) ^ int(col_digit))
and_sum += int(and_row, 2)
or_sum += int(or_row, 2)
xor_sum += int(xor_row, 2)
return and_sum + or_sum + xor_sum
#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
April 27, 2023