Last active
April 18, 2024 03:45
-
-
Save omas-public/c22c82ee176b6dc6e3485a35f9c2262f 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
_not = lambda p: not p | |
_and = lambda p, q: p and q | |
_or = lambda p, q: p or q | |
_xor = lambda p, q: not(p and q) and (p or q) | |
comparator = lambda fn: lambda list: fn(*list) | |
bit = [True, False] | |
twobit = [ | |
[False, False] | |
, [False, True] | |
, [True, False] | |
, [True, True] | |
] | |
print('not', list(map(_not, bit))) | |
print('and', list(map(comparator(_and), twobit))) | |
print('or' , list(map(comparator(_or), twobit))) | |
print('xor', list(map(comparator(_xor), twobit))) | |
# 抽象関数のみで実装 | |
T = lambda t: lambda f: t | |
F = lambda t: lambda f: f | |
N = lambda p: p(F)(T) | |
AND = lambda p: lambda q: p(q)(F) | |
OR = lambda p: lambda q: p(T)(q) | |
XOR = lambda p: lambda q: p(N(q))(q) | |
NAND= lambda p: lambda q: p(N(q))(T) | |
NOR = lambda p: lambda q: p(F)(N(q)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment