Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Nice and clean solution in Clear category for Multiplication Table by Vasily__Chibilyaev
def checkio(first, second):
AND=lambda x, y: x and y
OR=lambda x, y: x or y
XOR=lambda x, y: (not x and y) or (x and not y)
def logical_op(x, y, op):
return sum(int(''.join('1' if op(int(i), int(j)) else '0' for j in y), 2) for i in x)
first=bin(first)[2:]
second=bin(second)[2:]
operators=[AND, OR, XOR]
return sum(logical_op(first, second, op) for op in operators)
#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
Sept. 26, 2017