Classic Logic Puzzles: River Crossings, Knights and Knaves, and the Two Guards

Three of the oldest and best logic puzzles, with step-by-step solutions and the reasoning tricks behind them, so you can solve new versions on your own.

By Lavish Sethi · · 5 min read

Some puzzles have survived for more than a thousand years because they are short, fair and satisfying. You do not need maths, only careful thinking. This article walks through three classics, the river crossing, knights and knaves, and the two guards, and, more importantly, the habits of mind that crack them. Try each puzzle before reading the solution.

Puzzle 1: The wolf, the goat and the cabbage

A farmer needs to cross a river with a wolf, a goat and a cabbage. His boat can carry only the farmer and one item at a time. If left alone together:

  • the wolf will eat the goat, and
  • the goat will eat the cabbage.

The wolf has no interest in the cabbage. How does the farmer get everything across safely?

This puzzle is very old. A version appears in a collection of mathematical problems traditionally attributed to Alcuin of York, a scholar at the court of Charlemagne around the year 800.

Solution

The trick is realising that the goat is the troublemaker, because it is in conflict with both of the other items. And crucially, you are allowed to bring something back.

  1. Take the goat across. (Wolf and cabbage are safe together.)
  2. Return alone.
  3. Take the wolf across.
  4. Bring the goat back.
  5. Take the cabbage across. (Wolf and cabbage are together again, which is fine.)
  6. Return alone.
  7. Take the goat across.

That is seven crossings. You can also swap steps 3 and 5, taking the cabbage first and the wolf second; both work.

The lesson

Many people get stuck because they assume every trip should move things forward. The breakthrough is a "backward" move: returning the goat. When a puzzle seems impossible, question your hidden assumptions about what moves are allowed.

Puzzle 2: Knights and knaves

On a certain island, every inhabitant is either a knight, who always tells the truth, or a knave, who always lies. These puzzles were popularised by the logician and mathematician Raymond Smullyan in books such as What Is the Name of This Book? (1978).

Warm-up

You meet two islanders, A and B. A says: "We are both knaves."

What are A and B?

Solution: Suppose A is a knight. Then A's statement is true, so A is a knave. That is a contradiction, so A cannot be a knight. Therefore A is a knave, and the statement "we are both knaves" is false. Since A is a knave, the statement can only be false if B is not a knave. So B is a knight.

A harder one

You meet three islanders, C, D and E.

  • C says: "D is a knave."
  • D says: "C and E are the same type."
  • E says nothing.

What is E?

Solution: Work through the cases for C.

  • If C is a knight, C's statement is true, so D is a knave. D's statement is then false, so C and E are different types. C is a knight, so E is a knave.
  • If C is a knave, C's statement is false, so D is a knight. D's statement is then true, so C and E are the same type. C is a knave, so E is a knave.

Either way, E is a knave, even though we cannot tell what C and D are. It is a nice example of how a puzzle can have a definite answer to the question asked while leaving other things unknown.

The lesson

The key tool is case analysis: assume one possibility, follow the consequences, and see whether you reach a contradiction. If you do, the assumption was false. If both cases agree on something, that thing must be true.

Puzzle 3: The two guards

You stand before two doors. One leads to freedom, the other to a dungeon. Each door has a guard. One guard always tells the truth and the other always lies, but you do not know which is which. You may ask one question to one guard. What do you ask?

Solution

Point to either guard and ask:

"If I asked the other guard which door leads to freedom, which door would he point to?"

Then take the opposite door.

Why does this work? Consider both possibilities:

  • You asked the truth-teller. He truthfully reports what the liar would say. The liar would point to the dungeon, so the truth-teller points to the dungeon.
  • You asked the liar. The truth-teller would point to freedom, but the liar lies about that and points to the dungeon.

Either way, the answer you get points to the dungeon, so you go through the other door.

The lesson

The clever question routes the answer through both guards, so exactly one lie is always involved. A lie combined with the truth always produces a lie, which makes the answer reliably wrong, and a reliably wrong answer is just as useful as a reliably right one.

There is another valid approach: ask, "If I asked you whether the left door leads to freedom, would you say yes?" A truth-teller answers honestly; a liar, lying about his own lie, ends up answering truthfully as well. Logicians love this kind of double negation.

Habits that solve logic puzzles

Across all three puzzles, the same habits help:

  1. Write down the rules exactly. Many mistakes come from misremembering a condition.
  2. Question hidden assumptions. Can you move backwards? Can someone say nothing?
  3. Use case analysis. Try each possibility and look for contradictions.
  4. Look for the troublemaker. In the river crossing, the goat is the element in conflict with everything. Deal with it first.
  5. Check your answer against every rule before you declare victory.

Try these on your own

  • Jealous husbands (or missionaries and cannibals): three pairs must cross a river under rules about who can be left with whom. It is a harder relative of the wolf-goat-cabbage puzzle.
  • The fork in the road: one question to a single islander who could be a knight or a knave, to find the road to the village. Hint: it uses the same double-negative trick as the guards.
  • Water jugs: with a 3-litre and a 5-litre jug, measure exactly 4 litres.

Key takeaways

  • The wolf-goat-cabbage puzzle needs seven crossings and one "backward" trip with the goat.
  • Knights and knaves puzzles are solved by assuming a case and following it to a contradiction.
  • In the two guards puzzle, ask what the other guard would say, then take the opposite door.
  • Good puzzle solving is mostly careful reading, honest assumptions and patient case-checking.

Further reading: Raymond Smullyan, What Is the Name of This Book?; Wikipedia: River crossing puzzle.