Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
What's up, __doc__? solution in Creative category for Boolean Algebra by veky
def boolean(x, y, operation):
'''\
x | y | x∧y | x∨y | x→y | x⊕y | x≡y |
--------------------------------------
0 | 0 | 0 | 0 | 1 | 0 | 1 |
1 | 0 | 0 | 1 | 0 | 1 | 0 |
0 | 1 | 0 | 1 | 1 | 1 | 0 |
1 | 1 | 1 | 1 | 1 | 0 | 1 |
--------------------------------------'''
symbol = dict(
conjunction = "∧",
disjunction = "∨",
implication = "→",
equivalence = "≡",
exclusive = "⊕",
)[operation]
head, *body = boolean.__doc__.splitlines()
for line in body:
row = dict(zip(reversed(head), reversed(line)))
if (row['x'], row['y']) == (str(x), str(y)): return int(row[symbol])
Sept. 6, 2014
Comments: