Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
purely_functional solution in Uncategorized category for Multiplication Table by SlimeT
# migrated from python 2.7
# A rather functional solution
from operator import xor,and_,or_
i2b = lambda x: list(map(bool,list(map(int,bin(x)[2:])))) # 5 -> [True,False,True]
b2i = lambda x: int(''.join(map(str,list(map(int,x)))),2) # [True,False,True] -> 5
# Calculate the sum of a table
sumop = lambda f,x,y: sum([b2i([f(i,j) for j in i2b(y)]) for i in i2b(x)])
checkio = lambda x,y: sum(sumop(op,x,y) for op in [and_,or_,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
Feb. 16, 2014