On this page
A farmer has to take a wolf, a goat and a cabbage across a river. The boat holds the farmer and one passenger. Left alone, the wolf eats the goat and the goat eats the cabbage. The puzzle dates back to at least the 9th century, to a manuscript attributed to Alcuin of York, the *Propositiones ad Acuendos Juvenes* (Problems to sharpen the young).
Most people solve it by trial and error. Draw every position the puzzle can be in, though, and the answer becomes a path you can see, and the same drawing solves a whole family of puzzles.
How many states does the wolf, goat and cabbage puzzle have?
A state records which bank each of the four in the puzzle (farmer, wolf, goat, cabbage) is on. Each has two choices, so there are 2 × 2 × 2 × 2 = 16 states. We write a state as "start bank | far bank", so the start is FWGC | and the goal is | FWGC.
A state is unsafe when the goat is on a bank without the farmer and with the wolf or the cabbage. Fix the farmer's bank: the goat can be away from him with the wolf, with the cabbage, or with both. That gives 3 unsafe states with the farmer on each bank, so 6 unsafe and 10 safe states.
Now join two safe states with a line when one crossing (the farmer, alone or with one passenger) turns one into the other. You get a graph: a short chain from the start, a six-sided loop in the middle, and a short chain to the goal.
What is the shortest solution to the wolf, goat and cabbage puzzle?
The solution has seven crossings, four forward and three back. Ivars Peterson's *Science News* column "Tricky Crossings" also counts seven trips, and notes that another solution swaps the wolf and the cabbage. Each crossing is one step along the graph:
Take the goat across: WC | FG.
Return alone: FWC | G.
Take the wolf across: C | FWG.
Bring the goat back: FGC | W.
Take the cabbage across: G | FWC.
Return alone: FG | WC.
Take the goat across: | FWGC.
Step 4 is the move people miss: you carry something *back*. On the graph it is the only way forward from C | FWG. The first move is forced too, because every other option leaves the goat with the wolf or the cabbage. The two routes around the six-sided loop are the two seven-crossing solutions. No shorter path exists, because the start and the goal are seven steps apart on the graph.
How does the missionaries and cannibals puzzle work as a graph?
In the missionaries and cannibals puzzle, three missionaries and three cannibals cross with a boat that carries at most two people, and the cannibals may never outnumber the missionaries on a bank where missionaries are present.
Here the people of each kind are interchangeable, so a state only needs three numbers: missionaries on the start bank, cannibals on the start bank, and the side the boat is on. There are 16 ways to split them between the banks. Both banks are safe only when the start bank holds 0 or 3 missionaries, or equal numbers of each, which leaves 10 safe splits, each with the boat on either side.
A search from (3, 3, boat at start) to (0, 0, boat across) finds the answer in 11 crossings. Wikipedia lists an 11-trip solution and calls it one of four shortest solutions. Written as (missionaries, cannibals) in the boat:
Over (1, 1), back (1, 0), over (0, 2), back (0, 1)
Over (2, 0), back (1, 1), over (2, 0)
Back (0, 1), over (0, 2), back (1, 0), over (1, 1)
The hard move is the sixth: a missionary and a cannibal go back together.
Why does drawing the state graph solve river crossing puzzles?
The graph turns guessing into a search with an end: you list every position once, so you never repeat or miss one. Searching outward from the start, one crossing at a time, is called breadth-first search, and the first time it reaches the goal it has used the fewest crossings. Richard Bellman wrote about dynamic programming and "difficult crossing" puzzles in *Mathematics Magazine* in 1962, and Saul Amarel used missionaries and cannibals as an example of problem representation.
Try it on the next puzzle you meet:
Decide what a state must record, and nothing more.
Count the states, then cross out the unsafe ones.
Join states that one legal move connects.
Search from the start, level by level, until you reach the goal.
For more, see why the 15 puzzle with two tiles swapped can't be solved, how Hamiltonian cycles and the knight's tour use graphs, and how to tell two graphs apart. For worked problems that show each step of the reasoning, try the Fermi Problem Library, and look up graphs and counting in the Fermi Concept Library.



