• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jul 15th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. if __name__ == '__main__':
2.   # pythonの論理演算子を使った関数の実装
3.
4.   _not = lambda p: not p
5.   _and = lambda p, q: p and q
6.   _or  = lambda p, q: p or q
7.   _xor = lambda p, q: not(p and q) and (p or q)
8.   comparator = lambda fn: lambda list: fn(*list)
9.   bit = [True, False]
10.   twobit = [
11.     [False, False]
12.   , [False, True]
13.   , [True, False]
14.   , [True, True]
15.   ]
16.   print('not', list(map(_not, bit)))
17.   print('and', list(map(comparator(_and), twobit)))
18.   print('or' , list(map(comparator(_or), twobit)))
19.   print('xor', list(map(comparator(_xor), twobit)))
20.
21.   # 抽象関数のみで実装
22.   T = lambda t: lambda f: t
23.   F = lambda t: lambda f: f
24.   N = lambda p: p(F)(T)
25.
26.   AND = lambda p: lambda q: (p)(q)(F)
27.   OR  = lambda p: lambda q: (p)(T)(q)
28.   XOR = lambda p: lambda q: (p)(N(q))(q)
29.   NAND= lambda p: lambda q: (p)(N(q))(T)
30.   NOR = lambda p: lambda q: (p)(F)(N(q))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top