Ich versuche, eine einfache Formel mit einem NAND-Operator in einem Skript zu erstellen. Gibt es eine schnelle Möglichkeit, dies zu tun, oder muss ich eine Reihe von NOT- und AND-Operatoren verketten, um sie zu einem einzigen zu kombinieren?
JMP hat Und () Und alle () Funktionen, die ungefähr gleichwertig sind, und oder () Und beliebig () Funktionen, die ungefähr gleichwertig sind. Schreiben und(a,b,c) ist das gleiche wie a & b & c . Da ist auch ein nicht() Funktion, die mit ! identisch ist .
// definitions from wikipedia...
// NAND: a Boolean operator which gives the value zero if and only if
// all the operands have a value of one, and otherwise has a value of
// one (equivalent to NOT AND).
Show( !And( 1, 1, 1, 1, 0, 1, 1, 1 ) ); // 1
Show( Not( And( 1, 1, 1, 1, 1, 1, 1, 1 ) ) ); // 0
Show( !(1 & 1 & 1) ); // 0
// ALL() and AND() are similar, as are ANY() and OR()
Show( All( [1 1 1] ) ); // 1
Show( All( [1 0 1] ) ); // 0
Show( Any( [0 1 0] ) ); // 1
Show( Any( [0 0 0] ) ); // 0
// XOR: XOR gate (sometimes EOR, or EXOR and pronounced as
// Exclusive OR) is a digital logic gate that gives a true
// (1 or HIGH) output when the number of true inputs is odd.
//
// this one needs to promise only 1s and 0s for inputs
// because it is adding up the 1s to count them.
Show( Mod( Sum( 0, 0, 0, 0, 0, 0 ), 2 ) ); // 0
Show( Mod( Sum( 1, 1, 1, 1, 1, 1 ), 2 ) ); // 0
Show( Mod( Sum( 1, 1, 1, 0, 1, 1 ), 2 ) ); // 1
Show( Mod( Sum( 1, 1, 1, 1, 1, 1, 1 ), 2 ) ); // 1
Show( Mod( Sum( 1, 1, 1 ), 2 ) ); // 1
Show( Mod( Sum( 1, 0, 1 ), 2 ) ); // 0
Show( Mod( Sum( 0, 0 ), 2 ) ); // 0
Show( Mod( Sum( 0, 1 ), 2 ) ); // 1
Show( Mod( Sum( 1, 0 ), 2 ) ); // 1
Show( Mod( Sum( 1, 1 ), 2 ) ); // 0
Mir ist gerade klar geworden, dass dies eine dumme Frage ist, und ich habe ein not() um meine and-Aussage gesetzt.