# boolean-logic - 布尔运算ppt - 布尔运算规则

## 逻辑来测试3的4是真的 (18)

``````return (a+b+x+y) == 3;
``````

Java 8，过滤出错误的值，并计算剩余的真值：

``````public static long count(Boolean... values) {
return Arrays.stream(values).filter(t -> t).count();
}
``````

``````if (3 == count(a, b, c, d)) {
System.out.println("There... are... THREE... lights!");
}
``````

``````bool threeTrue = new[] { a, b, x, y }.Count(x => x) == 3;
``````

``````\$min = 6;
\$total = 10;

// create our boolean array values
\$arr = array_map(function(\$a){return mt_rand(0,1)>0;},range(1,\$total));

// the 'check'
\$arrbools = array_map(function(\$a){return (int)\$a;},\$arr);
\$conditionMet = array_sum(\$arrbools)>=\$min;

echo \$conditionMet ? "Passed" : "Failed";
``````

``````bool test(bool a, bool b, bool c, bool d){
int n1 = a ? 1 : 0;
int n2 = b ? 1 : 0;
int n3 = c ? 1 : 0;
int n4 = d ? 1 : 0;

return n1 + n2 + n3 + n4 == 3;
}
``````

``````return (a ? 1 : 0) + (b ? 1 : 0) + (C ? 1 : 0) + (d ? 1 : 0) == 3;
``````

``````bool test(bool *values, int n, int m){
int sum = 0;
for(int i = 0; i < m; i += 1){
sum += values[i] ? 1 : 0;
}
return sum == n;
}
``````

``````y = (x̄3 ^ x2 ^ x1 ^ x0) ∨ (x3 ^ x̄2 ^ x1 ^ x0) ∨ (x3 ^ x2 ^ x̄1 ^ x0) ∨ (x3 ^ x2 ^ x1 ^ x̄0)
``````

``````if [a, b, c, d].count(True) == 3:
``````

``````if [a, b, c, d].count(False) == 1:
``````

``````if [a, b, c, d].count(False) == True:
# In Python True == 1 and False == 0
``````

``````print [a, b, c, d].count(0) == 1
``````

``````print [a, b, c, d].count(1) == 3
``````

``````if a + b + c + d == 3:
``````

``````if sum([a, b, c, d]) == 3:
``````

``````if len(filter(bool, [a, b, c, d])) == 3:
``````

``````data = iter([a, b, c, d])
if not all(data) and all(data):
``````

``````if ((int)a + (int)b + (int)c + (int)d == 3)
...
``````

``````if ((a?1:0) + (b?1:0) + (c?1:0) + (d?1:0) == 3)
...
``````

``````bool exactly_three_true_from(bool cond1, bool cond2, bool cond3, bool cond4)
{
//...
}
``````

``````int t(boolean b) {
return (b) ? 1 : 0;
}

if (t(x) + t(y) + t(a) + t(b) == 3) return true;
return false;
``````

``````(a + b + c + d) == 3
``````

``````    static bool boolTester(int n, params bool[] values)
{
int sum = 0;

for (int i = 0; i < values.Length; i++)
{
if (values[i] == true)
{
sum += 1;
}
}
if( sum == n)
{
return true;
}
return false;
}
``````

``````        bool a = true;
bool b = true;
bool c = true;
bool d = false;

bool test = false;
test = boolTester(3, a, b, c, d);
``````

`````` a ? (b ? (c ^ d) : (c && d)) : (b && c && d)
``````

``````((a xor b) xor (c xor d)) and ((a or b) and (c or d))
``````

``````((a^b)^(x^y))&((a|b)&(x|y))
``````