Powershell, 36 34 byte
Ispirato da xnor , ma la sequenza *108%143%2
è più breve dell'originale*3%61%37%9%7%2
$args|% t*y|%{$n+=108*$_};$n%143%2
Script di prova:
$f = {
$args|% t*y|%{$n+=108*$_};$n%143%2
#$args|% t*y|%{$n+=3*$_};$n%61%37%9%7%2 # sequence by xnor
}
@(
,("AND 0 0", 0)
,("AND 0 1", 0)
,("AND 1 0", 0)
,("AND 1 1", 1)
,("XOR 0 0", 0)
,("XOR 0 1", 1)
,("XOR 1 0", 1)
,("XOR 1 1", 0)
,("OR 0 0", 0)
,("OR 0 1", 1)
,("OR 1 0", 1)
,("OR 1 1", 1)
,("NAND 0 0", 1)
,("NAND 0 1", 1)
,("NAND 1 0", 1)
,("NAND 1 1", 0)
,("NOR 0 0", 1)
,("NOR 0 1", 0)
,("NOR 1 0", 0)
,("NOR 1 1", 0)
,("XNOR 0 0", 1)
,("XNOR 0 1", 0)
,("XNOR 1 0", 0)
,("XNOR 1 1", 1)
) | % {
$s,$e = $_
$r = &$f $s
"$($r-eq$e): $s=$r"
}
Produzione:
True: AND 0 0=0
True: AND 0 1=0
True: AND 1 0=0
True: AND 1 1=1
True: XOR 0 0=0
True: XOR 0 1=1
True: XOR 1 0=1
True: XOR 1 1=0
True: OR 0 0=0
True: OR 0 1=1
True: OR 1 0=1
True: OR 1 1=1
True: NAND 0 0=1
True: NAND 0 1=1
True: NAND 1 0=1
True: NAND 1 1=0
True: NOR 0 0=1
True: NOR 0 1=0
True: NOR 1 0=0
True: NOR 1 1=0
True: XNOR 0 0=1
True: XNOR 0 1=0
True: XNOR 1 0=0
True: XNOR 1 1=1