Some F# to ponder:<p><pre><code> type LogicGate =
| ON
| OFF
| NAND of LogicGate * LogicGate
| NOT of LogicGate
| AND of LogicGate * LogicGate
| OR of LogicGate * LogicGate
| NOR of LogicGate * LogicGate
| XOR of LogicGate * LogicGate
| XNOR of LogicGate * LogicGate
let rec evaluate input =
match input with
| ON -> true
| OFF -> false
| NAND(a, b) -> not ((evaluate a) && (evaluate b))
| NOT(a) -> (evaluate (NAND(a, a)))
| AND(a, b) -> (evaluate (NOT(NAND(a, b))))
| OR(a, b) -> (evaluate (NAND(NOT(a), NOT(b))))
| NOR(a, b) -> (evaluate (NOT(OR(a, b))))
| XOR(a, b) -> (evaluate (AND(NAND(a, b), OR(a, b))))
| XNOR(a, b) -> (evaluate (NOT(XOR(a, b))))
[
NAND(OFF, OFF);
NAND(OFF, ON);
NAND(ON, OFF);
NAND(ON, ON)
] |> List.map (fun x -> printfn (evaluate x))</code></pre>