Skip to content

Instantly share code, notes, and snippets.

@vedgar
Created July 5, 2020 16:03
Show Gist options
  • Save vedgar/76aca3394bc64b6658ca126e115685d5 to your computer and use it in GitHub Desktop.
Save vedgar/76aca3394bc64b6658ca126e115685d5 to your computer and use it in GitHub Desktop.
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment