Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using bin() and eval() functions solution in Clear category for Multiplication Table by H0r4c3
def checkio(first, second):
result = 0
for oper in ('&', '|', '^'):
rows_sum = 0
for i in bin(first)[2:]:
rows = ''
for j in bin(second)[2:]:
rows += eval(f'str(int(i) {oper} int(j))')
rows_sum += int(rows, 2)
result += rows_sum
return result
#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
Jan. 28, 2022
Comments: