Quine – McCluskey
About a week ago I had a discussion with a fellow programmer about some boolean logic. We had three parameters, something like:
- personHasInsurence (A)
- personNeedsInsurence (B)
- personIsKnownAtThisAgency (C)
We also had two particulair cases for an insurance page:
Case 1:
Person has insurence and isn’t yet known at this agency
Case 2:
Person doesn’t have insurence, needs insurence and is known at this agency
Case 3:
Person doesn’t have insurence, doesn’t need insurence and is known at this agency
So the view-logic was a bit complex:
if( (A && !C) || (!A && B && C) || (!A && !B && C ) ) {
showPage();
}
Then I remebered something I learned at school some time ago. So called karnaugh maps. I’ve completely forgotten how to use them, but I knew it was possible to calculate the shortest form to comply to the logic rules. When looking further I found the so called “Quine McCluskey“-algorithm, and I decided to implement it (just to learn how it works).
Quine – McCluskey algorithm
First of, lets go through a couple of terms.
Category: Algorithms | Tags: Algorithms, Boolean logic, Quine | Comment (0)