Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean Expression [closed]

Tags:

logic

boolean

How can you express X of Y are true, in boolean logic? a rule like 2 of the following must be true (A, B, C, D, E, F) is it a form of multiplcation or set operations?
the end result is all the permutations like AB OR AC OR AD, if you said 3 of following it is like ABC, ABD, ABE, etc.. so it is like (A,B,C)^2?

thanks!

like image 453
Enigmae Avatar asked Jun 25 '26 16:06

Enigmae


2 Answers

In boolean logic (v is OR, ' following the predicate is NOT):

A B C'D'E'F' v
A B'C'D'E'F  v
A'B C'D'E'F' v
: : : : : :
<absolute bucketload of boolean expressions>
: : : : : :
A'B'C'D'E F

With permutations, there's a great many subexpressions you need to write.

Of course, if this is a programming question, you could just convert the booleans to 0 or 1, add them all up and ensure the result is 2.

like image 107
paxdiablo Avatar answered Jun 28 '26 07:06

paxdiablo


Assuming C# or some other language where bool != int:

bool nOf(int n, bool[] bs)
{
    foreach(bool b in bs)
    {
      if((n -= b ? 1 : 0) <= 0) break;
    }
    return n == 0;
}
like image 35
Patrick Avatar answered Jun 28 '26 07:06

Patrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!