Created
July 5, 2020 16:03
-
-
Save vedgar/76aca3394bc64b6658ca126e115685d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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