In [48]:
def nand(a, b):
return not a & b
In [49]:
def _and(a, b):
return a & b
In [50]:
def _or(a, b):
return a | b
In [51]:
def nor(a, b):
return not a | b
In [52]:
inputs = [(0, 0, 0),
(0, 0, 1),
(0, 1, 0),
(0, 1, 1),
(1, 0, 0),
(1, 0, 1),
(1, 1, 0),
(1, 1, 1)]
In [53]:
for a, b, c in inputs:
print((a & b) | (b & c) | (a & c))
In [54]:
inputs = [(0, 0),
(1, 0),
(0, 1),
(1, 1)]
In [55]:
for a, b in inputs:
print( not ((a & b) | ((not a) & (not b))) )
In [56]:
def circuit(s, i3, i2, i1, i0):
o3 = _and(not s, i2)
o2 = _or(_and(s, i3), _and(not s, i1))
o1 = _or(_and(i2, s), _and(not s, i0))
o0 = _and(i1, s)
return o3, o2, o1, o0
In [57]:
circuit(1, 1, 0, 1, 1)
Out[57]:
In [58]:
inputs = [(0, 0),
(1, 0),
(0, 1),
(1, 1)]
In [59]:
for a, b in inputs:
print(nand(nand(a, nand(a, b)), nand(b, nand(a, b))))
In [38]:
def circuit(a, b):
return _or(_and(not a, b), _and(not b, a))
In [39]:
for a, b in inputs:
for c in [0, 1]:
print(circuit(circuit(a, b), c))
In [45]:
inputs = [(0, 0, 0),
(0, 0, 1),
(0, 1, 0),
(0, 1, 1),
(1, 0, 0),
(1, 0, 1),
(1, 1, 0),
(1, 1, 1)]
In [47]:
for a, b, c in inputs:
print(_or(_and(not b, not c), _and(b, c)))