GenerateRandomSearch

Water Jug Puzzle Generator

A water-jug puzzle gives you unmarked jugs, a tap and a drain, and asks for an exact amount. With jugs of 5 and 3 litres you can measure 4 in six moves, and no fewer. This makes new puzzles with two or three jugs whose shortest answer falls in a range of moves you choose, or takes your own jugs and target, says plainly when the amount cannot be measured and why, and shows the shortest answer one move at a time.

What this generator does

Searches every state the jugs can reach, nearest first, so the first answer found has the fewest moves. For random puzzles it rejects targets that plain filling reaches (a multiple of one jug, or two jugs added together) and keeps those whose shortest answer is within your range.

How to use this tool

  1. Choose Make one for me, or enter your own jug sizes and the amount to measure.
  2. Press Make a puzzle and try it on paper.
  3. Press Show the first move, then Show the next move, to step through the shortest answer with the jugs drawn.

Understanding the controls

Puzzle
Make one for me picks jug sizes and a target; Use my own jugs and target solves the puzzle you type.
Jugs
Two or three jugs, each holding 2 to 20 litres. Three jugs allow targets two cannot reach, and usually shorter answers.
Fewest and most moves
The shortest answer must fall in this range. A tight range near 14 can fail to find a puzzle; the page says so and suggests widening it.
Puzzle code
Leave empty for a new puzzle from the browser's secure generator. With a code, the same code and settings make the same puzzle again; the code is a seed, not a secret.

Worked examples

Your own: jugs of 5 and 3, measure 4
Six moves, the fewest possible: fill the 5, pour into the 3, empty the 3, pour the 5 into the 3, fill the 5, pour into the 3 — 4 litres left in the 5.
Code harbour, two jugs, 4 to 8 moves
Jugs of 12 and 11 litres, measure 2: six moves, the fewest possible.
Jugs of 6 and 4, measure 3
Refused: every amount these jugs can hold is a multiple of 2.

Common use cases

  • A maths starter on measuring and remainders
  • Checking an answer to a puzzle someone set you
  • A printed puzzle with its answer for a quiz night

How this generator works

A state is how much each jug holds. From any state there are at most twelve moves with three jugs: fill one, empty one, or pour one into another until the first is empty or the second full. A breadth-first search visits every state in order of how many moves it takes to reach, so the first state with the target in a jug is reached by a shortest answer. If the search runs out of states, the target cannot be measured: every amount the jugs can hold is a multiple of the greatest common divisor of their sizes, which the page names. Afterwards the answer is replayed move by move with separately written pouring rules, and the set of states reachable in fewer moves is grown level by level to confirm the target is not among them.

Randomness and fairness

Jug sizes and targets come from the browser's secure generator, or a seeded one when you give a code. A code repeats a puzzle while the generator is unchanged. Codes are deterministic, not cryptographic.

For how randomness is produced across the whole site, see how Generate Random works.

Assumptions this tool makes

  • The jugs have no markings, and nothing can be judged by eye — a pour stops only when one jug is empty or the other full.
  • The target counts when it is in any one jug.

Limitations and good to know

  • Two or three jugs of up to 20 litres; the move count is capped at 14.
  • The answer shown is one of the shortest; another sequence of the same length may exist.
  • No difficulty grade is given beyond the move count, which measures length, not trickiness.

Common mistakes

Pouring 'about half'
Without markings the only exact amounts come from full, empty, or pouring until one of those happens.
Trying for an odd amount with two even jugs
Every amount reachable is a multiple of the jugs' greatest common divisor; the page checks this for you.

Practical tips

  • Pouring the bigger jug into the smaller one repeatedly walks through the remainders — a good first strategy.
  • Step through the answer with real cups of rice or water to make it concrete for a class.

Privacy and your data

The search runs in your browser. With analytics consent, a count records that a puzzle was made and how many moves its answer has; your jug sizes, target and code are never sent.