Hi! I want to collect the truth table output from “and gate” called with all four combinations of the two boolean inputs, i.e., [false, false, false, true]. Here is what I tried. Thanks in advance.
Here’s a Python program showing what I’m after.
def truth_table(fn):
bools = False, True
for a in bools:
for b in bools:
yield a, b, fn(a, b)
def and_gate(in1: bool, in2: bool) -> bool:
return in1 and in2
print(list(truth_table(and_gate)))
I confess that FLATTEN OF LIST ... is a little complicated; it's because you wanted the two inputs to AND in the result table as well as their AND. I'll have to think about how we can make that more friendly.