我正在嘗試在腳本中使用 NAND 運算符建立一個簡單的公式。 有沒有一種快速的方法可以做到這一點,或者我是否需要將一堆 NOT 和 AND 運算符連結在一起以合併為一個?
JMP 有和() 和全部() 函數大致等效,且或者() 和任何() 函數大致等效。寫作和(a,b,c)是相同的甲、乙、丙。 還有一個不是()功能與 ! 。
// 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
我剛剛意識到這是一個愚蠢的問題,並在我的 and 語句周圍加上了 not() 。