Language agnostic 特定布尔逻辑的帮助需求

Language agnostic 特定布尔逻辑的帮助需求,language-agnostic,logic,boolean,Language Agnostic,Logic,Boolean,现在,如何编写获得这些结果的逻辑?它看起来很简单,但我认为还不够。不,它真的很简单 CaptchaIsExist CaptchaIsValid = Result -------------- ------------- -------- true false = false Any other variations = true 不,很简单 CaptchaIsExist

现在,如何编写获得这些结果的逻辑?它看起来很简单,但我认为还不够。

不,它真的很简单

CaptchaIsExist    CaptchaIsValid   =   Result
--------------    -------------       --------
   true                false        =    false

   Any other variations             =    true

不,很简单

CaptchaIsExist    CaptchaIsValid   =   Result
--------------    -------------       --------
   true                false        =    false

   Any other variations             =    true

只需指定
false
的条件,并对其应用
not

bool Result = not (CaptchaIsExist and not CaptchaIsValid)

只需指定
false
的条件,并对其应用
not

bool Result = not (CaptchaIsExist and not CaptchaIsValid)
在类C伪代码中:

(not CaptchaIsExist) or CaptchaIsValid
在类C伪代码中:

(not CaptchaIsExist) or CaptchaIsValid

@Binary-Worrier解决方案的替代方案:

if (CaptchaIsExist && !CaptchaIsValid) then
    return false;
else
    return true;

我认为这更自然地表达了逻辑,也就是说,当你阅读它时,它传达了预期的逻辑。

替代@Binary Worrier的解决方案:

if (CaptchaIsExist && !CaptchaIsValid) then
    return false;
else
    return true;
bool Result = CaptchaIsValid OR NOT CaptchaIsExist

我认为这更自然地表达了逻辑,也就是说,当你阅读它时,它传达了预期的逻辑。

Result=!(CaptchaIsExist&(!CaptchaIsValid));结果=!(CaptchaIsExist&(!CaptchaIsValid));当
CaptchaIsValid=true
CaptchaIsExist=false
时,这是否会导致
true
,或者我遗漏了什么?如果captcha不存在,对其有效性的测试可能会失败。我认为最好颠倒测试顺序,假设语言使用短路求值。@Binary Worrier:是的,应该是这样的-四分之三的情况下结果应该是真的,只有一种情况下结果应该是假的,即CaptchaIsValid=FALSE和CaptchaIsExist=TRUE。(注意:如果你将德摩根法则应用于你的表达式,你会得到我的表达式,即它们是等价的。)@Paul R-它是否也等于(不是CaptchaIsExist)或CaptchaIsValid?@任何人:是的,求值顺序并不重要,假设这些只是简单的布尔值。当
CaptchaIsValid=true
CaptchaIsExist=false
时,这不是会导致
true
,还是我遗漏了什么?如果captcha不存在,其有效性测试可能会失败。我认为最好颠倒测试顺序,假设语言使用短路求值。@Binary Worrier:是的,应该是这样的-四分之三的情况下结果应该是真的,只有一种情况下结果应该是假的,即CaptchaIsValid=FALSE和CaptchaIsExist=TRUE。(注意:如果你将德摩根法则应用于你的表达式,你会得到我的表达式,即它们是等价的。)@Paul R-它是否也等于(不是CaptchaIsExist)或CaptchaIsValid?@任何人:是的,只要这些只是简单的布尔值,求值顺序并不重要。
bool Result = CaptchaIsValid OR NOT CaptchaIsExist