Skip to content

River Crossing Puzzle

Solve the classic wolf, goat, and cabbage crossing with touch and keyboard controls, explicit safety feedback, and a shortest route independently verified by breadth-first search.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Choose Farmer alone, Take wolf, Take goat, or Take cabbage; the passenger must be on the same bank as the farmer before the trip starts.
  2. 2.Cross without ever leaving wolf with goat or goat with cabbage on a bank that does not contain the farmer; an illegal attempt changes no positions.
  3. 3.Move all four entities to the far bank to earn exactly 1,000 points; the shortest route uses seven crossings, while two illegal attempts require Restart.

About River Crossing Puzzle

River Crossing Puzzle presents the classic wolf, goat, and cabbage problem as one compact, deterministic game. A farmer stands on the near bank with a wolf, a goat, and a cabbage. The goal is to move all four to the far bank. The farmer must pilot every crossing, and the boat can carry at most one of the other three passengers. A wolf and goat cannot remain together on a bank without the farmer, and a goat and cabbage cannot remain together without the farmer. Wolf and cabbage may safely share an unsupervised bank.

Those capacity and safety constraints come from the cited educational references. Julia Robinson Mathematics Festival describes the activity and its state-transition graph, while Margaret Fleck's University of Illinois computer science text independently develops the same puzzle as an example of state diagrams. The classic scenario and rules are not claimed as a Lizely invention. The screen layout, fixed 1,000-point reward, two-error stop, choice controls, keyboard mapping, messages, and boss key integration are product behavior created for this implementation.

The game displays a near bank and a far bank at the same time. Each person or object appears as a labeled token with its current bank exposed in the page's accessible state. The boat indicator points in the direction of the next crossing and always follows the farmer, because no animal or vegetable can pilot it. Choose Farmer alone, Take wolf, Take goat, or Take cabbage, then activate the crossing button. On a touchscreen, every choice and the main crossing action use a native button with a touch-friendly minimum height.

Keyboard play covers the entire route. Use Left or Up Arrow to move to the previous passenger option and Right or Down Arrow to move to the next one. Press Enter or Space to cross with the selected option. Number keys 1 through 4 are shortcuts that immediately cross with Farmer alone, wolf, goat, or cabbage respectively. The shared double-Escape boss key switches to the neutral spreadsheet view, and repeating the gesture returns to the same puzzle state.

An illegal attempt never quietly teleports a token. If the selected passenger is on the opposite bank from the farmer, the farmer, passenger, boat, and crossing counter all remain where they were. The live feedback explicitly says that the passenger is on the wrong bank. If a proposed crossing would strand wolf with goat or goat with cabbage without supervision, the same invariant holds: no positions change and the crossing counter does not increase. The feedback names the safety problem instead of pretending the trip occurred.

Each illegal attempt counts as one mistake. After the first, the route remains editable, so the player can choose another passenger and continue. A second illegal attempt deadlocks the run until Restart. This is a transparent game rule, not part of the historic riddle. Completion and deadlock are both frozen terminal states: passenger selectors, the crossing action, direct keyboard moves, and state changes stop affecting the result. Restart always restores all four entities to the near bank, places the boat with the farmer, selects goat as the initial choice, and resets crossings, mistakes, score, and feedback.

A correct completion always awards exactly 1,000 points. The score does not claim that a longer safe route is impossible, and it does not rate intelligence or ability. The classic graph permits walks that revisit states, so a player can deliberately undo progress and still finish later. The shortest solution takes seven crossings. Reaching the far bank safely in any number of legal crossings completes the product game, while the disclosed shortest length provides a useful goal for players who want an efficient route.

The implementation represents a river arrangement as four bits in farmer, wolf, goat, cabbage order. Zero means near bank and one means far bank, making the initial state 0000 and the goal 1111. For every one of the 16 possible bit arrangements, the safety validator checks each bank that lacks the farmer. It rejects that arrangement if wolf and goat are both present or if goat and cabbage are both present. Exactly 10 arrangements survive, matching the published graph discussed by the cited sources.

Legal transitions are then generated explicitly. The candidate passenger is either nobody, wolf, goat, or cabbage. A nonempty passenger must begin on the farmer's current bank. The transition flips the farmer's side and, when present, that passenger's side. The resulting arrangement must pass the same safety validator. This produces an unweighted state graph whose vertices are the 10 safe arrangements and whose edges are legal boat crossings. Because crossing the river is reversible under the same constraints, the graph supports forward trips and necessary return trips without a special-case script.

Breadth-first search starts at 0000 and explores legal graph edges one crossing at a time. The first depth at which 1111 appears is seven. Retaining equal-depth alternatives produces exactly two shortest routes. One is goat, farmer alone, wolf, goat back, cabbage, farmer alone, goat. The other swaps the wolf and cabbage outward trips. Both routes begin with the goat, because carrying wolf first would abandon goat with cabbage, carrying cabbage first would abandon wolf with goat, and crossing alone would abandon both dangerous pairs.

Release tests do not accept the production BFS as its own proof. An independent oracle encodes the four positions as numeric bits, implements safety directly from pair equality, generates moves with numeric passenger indexes, and performs a separate queue search. The oracle independently finds 10 safe arrangements, a minimum depth of seven, and two shortest routes. Tests compare the complete minimum route set against the product search, verify every state along a disclosed golden sequence, and confirm that the finished route reaches 1111 at exactly 1,000 points.

Additional golden checks cover concrete rule boundaries. They confirm that 0000 is safe under farmer supervision, 1000 is unsafe because the farmer has left all three behind, and 1100 is unsafe because goat and cabbage are unsupervised. They prove that goat may cross first to 1010, while first crossings with wolf or cabbage are rejected. They also attempt to carry an item from the opposite bank, verify that neither positions nor crossing count changes after rejected moves, exercise the two-error deadlock, and prove that terminal states ignore further input.

Everything runs locally in the browser. No move history or score is uploaded, no account is needed, no random puzzle is fetched, and no new runtime dependency is used. The fixed rules and graph make results reproducible across reloads. Native controls, visible focus behavior, live feedback, readable bank labels, and compact responsive columns support keyboard, touch, and assistive-technology use. The three-column river layout uses shrink-safe bank panels so long labels do not force horizontal page overflow on a 390-pixel viewport.

This game is recreational entertainment. It is not an intelligence test, aptitude measure, educational placement exam, psychological instrument, hiring screen, or health assessment. The fixed riddle becomes familiar after repeated play, mistakes can come from a key slip, and the product score is not normed against any population. For a first solve, ask which passenger can be left apart from both threats. Then treat each return trip as a graph edge: sometimes apparent backward motion is the only safe way to prepare the next outward cargo.

Methodology & sources

Encode each arrangement as a four-bit farmer-wolf-goat-cabbage key. Reject either bank when it lacks the farmer but contains wolf with goat or goat with cabbage. Enumerate all 16 keys to obtain the 10 safe states, then generate an edge only when the farmer and optional passenger depart from the same bank and the resulting state remains safe. Run breadth-first search from 0000 to 1111, retaining equal-depth paths, to confirm exactly two shortest solutions of seven crossings. Cross-check with an independent numeric-bit oracle and disclosed golden states. Runtime play preserves positions and crossing count on invalid input, counts two invalid attempts as deadlock, awards exactly 1,000 at the safe goal, freezes terminal states, and restores a clean initial state on Restart.

Frequently asked questions

How many passengers fit in the boat?
The farmer must pilot every crossing and may carry at most one of wolf, goat, or cabbage. The farmer may also return alone when the resulting banks remain safe.
Which pairs are dangerous without the farmer?
Wolf with goat is unsafe, and goat with cabbage is unsafe. Wolf and cabbage may remain together without supervision.
What is the shortest solution length?
Breadth-first search over the 10 legal states finds two shortest routes, each seven crossings. Both start by taking the goat.
Does the score measure reasoning ability?
No. The 1,000-point reward and two-error stop are Lizely game behavior. This familiar fixed puzzle is entertainment, not a standardized intelligence, education, employment, health, or psychological assessment.

Mini Games guides

View all