Getting everyone across sounds simple. A small boat, a maximum load, incompatible companions or a torch that must return make it harder. Such problems do not always require a flash of inspiration: we can describe them precisely and systematically search for a route.

Before the moves: define the puzzle properly
For each problem we specify who can row, the boat’s capacity, whether the limit concerns seats or weight, where incompatibilities apply and whether empty trips are allowed. Everyone starts on the initial bank; everyone finishes on the final bank with the boat or torch there too. A return is not free: it is a move, and on the bridge it also takes time.
From a story to a state graph
A state records the location of each item and the transport. In wolf–goat–cabbage, four L/R letters suffice, ordered farmer, wolf, goat, cabbage: the boat always accompanies the farmer. Merely counting people does not distinguish couples, however. On the island each item has three possible locations. An edge is a crossing that satisfies every constraint; we are not just connecting similar pictures.
Not all 16 combinations of four items are legal or reachable. Representing the state correctly comes before choosing the algorithm: a perfect solver of the wrong model answers a different question.
BFS: why it finds the fewest crossings
Breadth-first search uses a queue. It starts at the initial situation, generates legal moves, marks new states when enqueueing them and stores a predecessor for each. First it examines all states one crossing away, then those two crossings away, and so on. On first reaching the goal, no shorter route can remain unexplored. Following predecessors backwards reconstructs the moves.
- Put the initial state in the queue and visited set.
- Remove the first state. If it is the goal, reconstruct the route.
- Generate all legal crossings; enqueue only unvisited states and record where they came from.
- Repeat. If the queue empties, the goal is unreachable in this finite model.
Dijkstra: when crossings have different costs
On the bridge, C and D crossing costs 10 minutes, while A returning costs 1. BFS minimizes edges, not minutes. Dijkstra repeatedly chooses the unexamined situation with the least accumulated cost and improves distances when it finds a cheaper route. With nonnegative costs, when the goal’s distance becomes final, its time is minimal. The constraints stay the same: what changes is the order of graph exploration.
Do not confuse the boat’s weight limit with route cost: in the family puzzle kilograms determine whether a move is permitted; they are not minutes and are not added to measure solution quality.
The collection: try before opening the solutions
The tables give one optimal route, not necessarily the only one. In the laboratory you may choose different equivalent people or a different order: a different solution need not be wrong. The island and family puzzles are teaching variants under the rules stated here.
- 1. Wolf, goat and cabbage
- 2. Three missionaries and three cannibals
- 3. Three jealous couples
- 4. Three soldiers and two children
- 5. A family and a 100 kg limit
- 6. Bridge and torch: 1, 2, 5, 10 minutes
- 7. Using an island as a staging point
- 8. Four and four: can it be done?
1. Wolf, goat and cabbage
Everyone starts on the starting bank and must reach the other. Only the farmer rows; the boat carries the farmer and at most one other item. On either bank, wolf and goat or goat and cabbage cannot be left together without the farmer. The farmer may return alone. Minimize crossings.
Try this puzzle in the laboratory
A hint without the solution
Which item cannot be left with either of its two neighbours? Why might it need to come back even after reaching the far bank?
Solution, explanation and optimality check
Optimum: 7 crossings.
| Step | Who crosses | Route |
|---|---|---|
| 1 | Farmer, Goat | Starting bank → Destination bank |
| 2 | Farmer | Destination bank → Starting bank |
| 3 | Farmer, Wolf | Starting bank → Destination bank |
| 4 | Farmer, Goat | Destination bank → Starting bank |
| 5 | Farmer, Cabbage | Starting bank → Destination bank |
| 6 | Farmer | Destination bank → Starting bank |
| 7 | Farmer, Goat | Starting bank → Destination bank |
The goat must go first. After taking the wolf across, bringing the goat back is not wasteful: it allows the cabbage to cross without leaving a forbidden pair. The shortest route takes 7 crossings. This is a global choice, not a rule of always leaving more items on the destination bank.
2. Three missionaries and three cannibals
Three missionaries and three cannibals must reach the destination bank. The boat carries one or two people, and everyone can row. On either bank and in the boat, cannibals must not outnumber missionaries where any missionaries are present; with no missionaries, any number of cannibals is allowed. Nobody swims and the boat never travels empty. Minimize crossings.
Try this puzzle in the laboratory
A hint without the solution
Checking the destination bank is not enough: what balance between the groups are you leaving behind?
Solution, explanation and optimality check
Optimum: 11 crossings.
| Step | Who crosses | Route |
|---|---|---|
| 1 | Missionary M1, Cannibal C1 | Starting bank → Destination bank |
| 2 | Missionary M1 | Destination bank → Starting bank |
| 3 | Cannibal C2, Cannibal C3 | Starting bank → Destination bank |
| 4 | Cannibal C1 | Destination bank → Starting bank |
| 5 | Missionary M1, Missionary M2 | Starting bank → Destination bank |
| 6 | Missionary M1, Cannibal C2 | Destination bank → Starting bank |
| 7 | Missionary M1, Missionary M3 | Starting bank → Destination bank |
| 8 | Cannibal C3 | Destination bank → Starting bank |
| 9 | Cannibal C1, Cannibal C2 | Starting bank → Destination bank |
| 10 | Missionary M1 | Destination bank → Starting bank |
| 11 | Missionary M1, Cannibal C3 | Starting bank → Destination bank |
For equivalent people we can count missionaries and cannibals on one bank and record the boat’s position. The laboratory also distinguishes individuals so they can be selected; this increases the states but does not change the optimum. BFS finds 11 crossings: every situation reachable in fewer crossings is considered before the goal.
3. Three jealous couples
Three couples must reach the other bank with a boat carrying one or two people; anyone may row. Under this traditional puzzle’s constraint, no wife may be with another husband unless her own is present. Check both banks and the passengers in the boat; a wife alone or with only wives is allowed. Passengers disembark together on arrival. Minimize crossings.
Try this puzzle in the laboratory
A hint without the solution
Two groups with the same numbers of husbands and wives need not be equivalent: who is married to whom matters.
Solution, explanation and optimality check
Optimum: 11 crossings.
| Step | Who crosses | Route |
|---|---|---|
| 1 | Husband 1, Wife 1 | Starting bank → Destination bank |
| 2 | Husband 1 | Destination bank → Starting bank |
| 3 | Wife 2, Wife 3 | Starting bank → Destination bank |
| 4 | Wife 1 | Destination bank → Starting bank |
| 5 | Husband 2, Husband 3 | Starting bank → Destination bank |
| 6 | Husband 2, Wife 2 | Destination bank → Starting bank |
| 7 | Husband 1, Husband 2 | Starting bank → Destination bank |
| 8 | Wife 3 | Destination bank → Starting bank |
| 9 | Wife 1, Wife 2 | Starting bank → Destination bank |
| 10 | Wife 1 | Destination bank → Starting bank |
| 11 | Wife 1, Wife 3 | Starting bank → Destination bank |
Counting men and women alone is insufficient. The state must retain couple identities; otherwise a program might accept a numerically balanced but forbidden bank. Applying the stated constraint in the boat as well, search finds a minimum of 11 crossings. The constraint belongs to the traditional game, not to a rule of behaviour.
4. Three soldiers and two children
Three soldiers and two children must cross a river. Everyone can row. The boat supports two children or one soldier; a single child is allowed, but a soldier and a child together are not. The boat cannot travel empty and nobody swims. Both children must finish on the destination bank too. Minimize crossings.
Try this puzzle in the laboratory
A hint without the solution
The two children can deliver the boat and bring it back. How can a cycle transfer one soldier?
Solution, explanation and optimality check
Optimum: 13 crossings.
| Step | Who crosses | Route |
|---|---|---|
| 1 | Child R1, Child R2 | Starting bank → Destination bank |
| 2 | Child R1 | Destination bank → Starting bank |
| 3 | Soldier S1 | Starting bank → Destination bank |
| 4 | Child R2 | Destination bank → Starting bank |
| 5 | Child R1, Child R2 | Starting bank → Destination bank |
| 6 | Child R1 | Destination bank → Starting bank |
| 7 | Soldier S2 | Starting bank → Destination bank |
| 8 | Child R2 | Destination bank → Starting bank |
| 9 | Child R1, Child R2 | Starting bank → Destination bank |
| 10 | Child R1 | Destination bank → Starting bank |
| 11 | Soldier S3 | Starting bank → Destination bank |
| 12 | Child R2 | Destination bank → Starting bank |
| 13 | Child R1, Child R2 | Starting bank → Destination bank |
Before a soldier crosses, both children cross and one returns. After the soldier crosses, the other child returns: the soldier stays transferred and the children can repeat the shuttle. Each soldier needs four crossings; after all three have crossed, the children cross together once more. Total 4 · 3 + 1 = 13, matching the BFS optimum.
5. A family and a 100 kg limit
Ada weighs 75 kg, Bruno 65, Carla 40, Diego 30 and Elia 20. Everyone can row and must reach the other bank. The boat supports at most 100 kg: there is no additional two-person limit. Any nonempty group within the weight limit may travel; there are no incompatibilities on the banks. Minimize crossings.
Try this puzzle in the laboratory
A hint without the solution
The last three weigh 90 kg together. The largest group is not necessarily too heavy.
Solution, explanation and optimality check
Optimum: 5 crossings.
| Step | Who crosses | Route |
|---|---|---|
| 1 | Bruno, Diego | Starting bank → Destination bank |
| 2 | Diego | Destination bank → Starting bank |
| 3 | Ada, Elia | Starting bank → Destination bank |
| 4 | Elia | Destination bank → Starting bank |
| 5 | Carla, Diego, Elia | Starting bank → Destination bank |
One solution sends Bruno and Diego, returns Diego, sends Ada and Elia, returns Elia, and finishes with Carla, Diego and Elia. The loads are 95, 30, 95, 20 and 90 kg. BFS certifies the minimum of 5 crossings. Counting people alone would wrongly exclude the final trip with three: weight is the constraint here.
6. Bridge and torch: 1, 2, 5, 10 minutes
Four people take 1, 2, 5 and 10 minutes respectively to cross a bridge. One or two cross at a time, always with the only torch; a pair takes the slower person’s time. Someone must carry the torch back; it cannot be thrown. Everyone starts together and must reach the other side. Minimize total time, not just the number of crossings.
Try this puzzle in the laboratory
A hint without the solution
Should the two slowest cross separately or together? Which return trip needs to have been prepared already?
Solution, explanation and optimality check
Optimum: 17 minutes.
| Step | Who crosses | Route | Duration | Total time |
|---|---|---|---|---|
| 1 | A · 1 min, B · 2 min | Starting bank → Destination bank | 2 min | 2 min |
| 2 | A · 1 min | Destination bank → Starting bank | 1 min | 3 min |
| 3 | C · 5 min, D · 10 min | Starting bank → Destination bank | 10 min | 13 min |
| 4 | B · 2 min | Destination bank → Starting bank | 2 min | 15 min |
| 5 | A · 1 min, B · 2 min | Starting bank → Destination bank | 2 min | 17 min |
A and B cross in 2 minutes; A returns in 1; C and D cross in 10; B returns in 2; A and B cross in 2. Total 2 + 1 + 10 + 2 + 2 = 17 minutes. Always using A as escort would give 2 + 1 + 5 + 1 + 10 = 19 instead. Both strategies have 5 crossings: BFS does not distinguish their times, but Dijkstra does.
7. Using an island as a staging point
Teaching variant: the farmer, wolf, goat and cabbage start on the initial bank and must reach the final bank via an island. Only starting bank–island and island–final bank journeys are allowed, in either direction. Each leg counts as one crossing. The boat carries the farmer and at most one other item. On all three land areas, wolf–goat and goat–cabbage cannot remain together without the farmer. Items may be left on the island. Minimize legs.
Try this puzzle in the laboratory
A hint without the solution
The island is not merely a compulsory stop: it can hold one item while you escort another all the way across.
Solution, explanation and optimality check
Optimum: 10 crossings.
| Step | Who crosses | Route |
|---|---|---|
| 1 | Farmer, Goat | Starting bank → Island |
| 2 | Farmer | Island → Starting bank |
| 3 | Farmer, Wolf | Starting bank → Island |
| 4 | Farmer, Wolf | Island → Destination bank |
| 5 | Farmer | Destination bank → Island |
| 6 | Farmer | Island → Starting bank |
| 7 | Farmer, Cabbage | Starting bank → Island |
| 8 | Farmer, Cabbage | Island → Destination bank |
| 9 | Farmer | Destination bank → Island |
| 10 | Farmer, Goat | Island → Destination bank |
One solution first leaves the goat on the island, takes the wolf to the final bank, returns for the cabbage and takes it all the way across; only then is the goat collected from the island. The minimum is 10 legs, not 14: mechanically doubling the original 7 crossings misses the new staging point. The model now retains three possible locations per item and forbids direct travel between the outer banks.
8. Four and four: can it be done?
Four missionaries and four cannibals start on the same bank. The boat carries one or two people and everyone can row. On either bank and in the boat, cannibals must not outnumber missionaries where missionaries are present. The boat never travels empty and nobody swims. Can everyone cross? Do not assume repeating the three-and-three method is enough.
Try this puzzle in the laboratory
A hint without the solution
More people change the graph. When a search fails to reach the goal, has it exhausted all states or merely been stopped early?
Solution, explanation and optimality check
Impossible: all 98 reachable states were examined without finding the goal.
There is no solution under these rules. In the laboratory model, which distinguishes all eight people, BFS examines all 98 states reachable from the start without encountering the goal. This is not a conclusion based on a few failed attempts: the frontier is exhausted. The proof concerns this exact capacity and these constraints; increasing the boat’s capacity creates a different puzzle.
What the algorithm really guarantees
For the constructed graph, BFS takes O(V + E) time and O(V) memory, with V states and E legal moves; generating candidate loads has its own cost too. With a binary priority queue, Dijkstra takes O((V + E) log V). These bounds refer to the graph, which can grow exponentially with the number of items. A safety cutoff therefore does not prove impossibility. Our eight cases are small and are explored exhaustively when required.
Using the laboratory
Choose a puzzle and try moves: an illegal attempt is explained without changing the situation. Undo or restart at any time. A hint searches for one next move on an optimal route from your current situation; Check the optimum compares with the initial state. Opening the solution enters a separate replay, one move at a time, with a table and counters. Close it to recover your game. On the bridge compare the fewest-crossings objective with the least-minutes objective.
Going back may be the necessary progress
The common thread is not a sequence to memorize but a method: describe the state, generate legal moves, avoid cycles and choose an optimization criterion. Bringing the boat back need not make a strategy worse. Mathematics distinguishes a locally tempting move from a globally correct and optimal route.
Also explore the weighted-graph laboratory