# There are four combinations of a and b

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the algorithms category.

Last Updated: 2023-12-03

When programming a job market, a candidate had a boolean column for "fulltime" and another one for "parttime". I then built filters based on this structure and had the following logic:

``````<? php

if (array_key_exists("full_time", \$filterParams) && array_key_exists("part_time", \$filterParams)) {
// We think of the combination of part_time and full_time as logical OR instead of AND (which we
// use with the rest of the filters). Therefore we add no filters
// here.
} elseif (array_key_exists("part_time", \$filterParams)) {
\$query->where("part_time", \$filterParams["part_time"]);
} else {
\$query->where("full_time", \$filterParams["full_time"]);
}
``````

Strictly speaking, this was incomplete. Whenever a candidate was neither full-time nor part-time, the final else statement would be executed, and they would show up in searches for exclusively full-time.

# Lesson

How many possible combinations are there of A and B? Not three, as I assumed.

But four. There are going to be 2^N possible combinations. You can work this out by thinking of there being N slots (2 in this case), and each slot can be either ON or OFF. Therefore

• A !B
• !A B
• !A !B
• A B