For example, the gate A and B is a logic gate with 2 inputs and 1 output.
There are exactly 16 of them, because:
- each logic gate takes two inputs, which can be truthy or falsey, giving us 4 possible inputs
- of the 4 possible inputs, each can have an output of truthy and falsey
- therefore, there are 2^4 possible logic gates, which is 16.
Your task is to write 16 programs/functions which implement all of them separately.
Your functions/programs must be independent.
They are valid as long as they output truthy/falsey values, meaning that you can implement A or B in Python as lambda a,b:a+b, even if 2 is produced for A=True and B=True.
Score is total bytes used for each function/program.
List of logic gates
- 0,0,0,0 (
false) - 0,0,0,1 (
and) - 0,0,1,0
- 0,0,1,1 (
A) - 0,1,0,0
- 0,1,0,1 (
B) - 0,1,1,0 (
xor) - 0,1,1,1 (
or) - 1,0,0,0 (
nor) - 1,0,0,1 (
xnor) - 1,0,1,0 (
not B) - 1,0,1,1 (
if B then A) - 1,1,0,0 (
not A) - 1,1,0,1 (
if A then B) - 1,1,1,0 (
nand) - 1,1,1,1 (
true)
Where the first number is the output for A=false, B=false,
the second number is the output for A=false, B=true,
the third number is the output for A=true, B=false,
the fourth number is the output for A=true, B=true.



f? – Dennis♦ 2 days ago