Looking for a boolean puzzle

574 Views Asked by At

I'm teaching a class on coding, covering boolean algebra, and I want to give something fun and a bit challenging for homework. Can somebody suggest a relatively simple logical puzzle that is solved by constructing a boolean expression. Maybe 4-5 input variables would be appropriate size. It should have a fun text, if possible

1

There are 1 best solutions below

0
On BEST ANSWER

Here's an example of formulating a simple "knights and knaves" puzzle using Boolean expressions.

Consider the "Fork in the Road" puzzle:

John and Bill are standing at a fork in the road. John is standing in front of the left road, and Bill is standing in front of the right road. One of them is a knight and the other a knave, but you don't know which. You also know that one road leads to Death, and the other leads to Freedom. By asking one yes–no question, can you determine the road to Freedom?

Boolean variables:

  • $L$: the left road leads to Freedom
  • $J$: John is the knight

You decide to ask John a question of the form "If I asked Bill $\ldots$, would he say Yes?"

So new variables:

  • $Q$: the true answer to the question to ask Bill
  • $R$: Bill's answer to that question
  • $S$: John's answer to your question

Then: $$ \eqalign {R &= (Q \cap \neg J) \cup (\neg Q \cap J)\cr S &= (R \cap J) \cup (\neg R \cap \neg J)}$$

Simplify to: $S = \neg Q$. So you can make $Q = \neg L$ (i.e. ask John "If I asked Bill 'does the right road lead to Freedom', would he say Yes?"), and take John's answer as indicating whether the left road leads to Freedom.