Skip to content
One Quick Try

Water Jug Puzzle

Fill, empty and pour unmarked jugs until one of them holds exactly the amount asked for.

Type
Logic
Takes
about 1-4 min
Result in
moves

Water Jug

~1-4 min

  1. Get exactly the amount asked for into any one jug.
  2. Fill a jug from the tap, empty it, or pour one jug into another. The jugs have no markings.
  3. A pour stops when the first jug is empty or the second is full.
Puzzle
Jugs of 3 and 5 liters → measure 4

The clock starts on your first move.

Your result: — moves

How it's measured
  • River Crossing

    Get everyone across the river safely.~2-5 min
  • Tower of Hanoi

    Move every disk in the fewest moves.~1-5 min
  • Lights Out

    Turn off every light. Each press flips its neighbors.~1-3 min
  • Make 24

    Use all four numbers to make 24.~2-4 min
  • Traffic Jam

    Slide the cars to free the red one.~2-6 min
  • Shape Equations

    Each shape is a number. Work them out.~2-4 min

What is the water jug puzzle?

The water jug puzzle asks you to measure an exact amount of water using only jugs of known size that have no markings. A jug can be filled to the brim, emptied, or poured into another jug until the first is empty or the second is full. Nothing else can be measured, so you have to plan a chain of fills, pours and empties that leaves exactly the right amount behind.

How to play it here

Pick one of the 8 puzzles and press Start. Each jug has a Fill and an Empty button under it. To pour, tap the jug you want to pour from, then the jug you want to pour into; tap the first jug again, or press Escape, to change your mind. A move that would change nothing, such as filling a jug that is already full, is refused and doesn't count. You win as soon as any jug holds exactly the target amount.

The 8 puzzles

They get harder in order. The fewest moves for each was found by computer, as explained below.

PuzzleJugs (liters)MeasureFewest moves
13 and 54 liters6
24 and 96 liters8
35, 7 and 1211 liters9
48 and 136 liters10
55, 9 and 147 liters12
67 and 119 liters16
79 and 1311 liters20
811 and 1513 liters24

How is your result calculated?

Every fill, empty and pour is one move. The clock starts on your first move, not when you press Start, so time spent planning is free, and it stops on the move that leaves the target amount in a jug. You see your moves, your time, and the fewest moves possible.

The fewest moves is a true minimum, not an estimate. Starting from empty jugs, your browser lists every state the jugs can reach in one move, then every state reachable in two, and so on (a breadth-first search). The first time a state with the target amount turns up, the number of moves taken to reach it is the minimum.

How do you measure 4 liters with 3 and 5 liter jugs?

This is the classic version, and puzzle 1 here. It takes 6 moves at best, by repeatedly filling the bigger jug and pouring it into the smaller one:

  1. Fill the 5 liter jug. The jugs now hold 0 and 5 liters.
  2. Pour the 5 liter jug into the 3 liter jug. The jugs now hold 3 and 2 liters.
  3. Empty the 3 liter jug. The jugs now hold 0 and 2 liters.
  4. Pour the 5 liter jug into the 3 liter jug. The jugs now hold 2 and 0 liters.
  5. Fill the 5 liter jug. The jugs now hold 2 and 5 liters.
  6. Pour the 5 liter jug into the 3 liter jug. The jugs now hold 3 and 4 liters.

The same puzzle appears in the 1995 film Die Hard with a Vengeance, with gallons instead of liters: the heroes have to put exactly 4 gallons on a scale to stop a bomb.

What does my rating mean?

Each solve is rated on your moves against that puzzle's fewest possible: exactly the fewest is Perfect, and each extra move lowers the rating. The moves that earn each rating, puzzle by puzzle:

Puzzle (moves)PerfectExcellentGoodFairKeep trying
16–7–89–1011+
2891011–1415+
391011–1213–1617+
4101112–1314–1819+
5121314–1617–2122+
61617–1819–2122–2829+
72021–2324–2728–3637+
82425–2728–3233–4344+

The 8-5-3 and 10-7-3 jug puzzles

Some jug puzzles have no tap and no drain: all the water starts in the biggest jug, and you can only pour between jugs. The most famous asks you to share 8 liters equally using jugs of 8, 5 and 3 liters. These are the shortest solutions, worked out by the same search that finds the fewest moves for the puzzles above:

Jugs of 8, 5 and 3 liters: share 8 liters equally (7 pours)

  1. Pour the 8 liter jug into the 5 liter jug. The jugs now hold 3, 5, 0 liters.
  2. Pour the 5 liter jug into the 3 liter jug. The jugs now hold 3, 2, 3 liters.
  3. Pour the 3 liter jug into the 8 liter jug. The jugs now hold 6, 2, 0 liters.
  4. Pour the 5 liter jug into the 3 liter jug. The jugs now hold 6, 0, 2 liters.
  5. Pour the 8 liter jug into the 5 liter jug. The jugs now hold 1, 5, 2 liters.
  6. Pour the 5 liter jug into the 3 liter jug. The jugs now hold 1, 4, 3 liters.
  7. Pour the 3 liter jug into the 8 liter jug. The jugs now hold 4, 4, 0 liters.

Jugs of 10, 7 and 3 liters: share 10 liters equally (9 pours)

  1. Pour the 10 liter jug into the 7 liter jug. The jugs now hold 3, 7, 0 liters.
  2. Pour the 7 liter jug into the 3 liter jug. The jugs now hold 3, 4, 3 liters.
  3. Pour the 3 liter jug into the 10 liter jug. The jugs now hold 6, 4, 0 liters.
  4. Pour the 7 liter jug into the 3 liter jug. The jugs now hold 6, 1, 3 liters.
  5. Pour the 3 liter jug into the 10 liter jug. The jugs now hold 9, 1, 0 liters.
  6. Pour the 7 liter jug into the 3 liter jug. The jugs now hold 9, 0, 1 liters.
  7. Pour the 10 liter jug into the 7 liter jug. The jugs now hold 2, 7, 1 liters.
  8. Pour the 7 liter jug into the 3 liter jug. The jugs now hold 2, 5, 3 liters.
  9. Pour the 3 liter jug into the 10 liter jug. The jugs now hold 5, 5, 0 liters.

Which amounts can you measure?

With two jugs you can measure exactly the whole-number amounts that are multiples of the two sizes' greatest common divisor, up to the size of the bigger jug. Every fill, empty and pour moves water in whole jugfuls or in the leftovers of earlier pours, so the amounts you can reach are all made by adding and subtracting the jug sizes. That rule is Bézout's identity from number theory.

So with jugs of 4 and 6 liters, whose greatest common divisor is 2, every amount you can measure is even: 1 or 3 liters is impossible however long you pour. With 3 and 5 liters the greatest common divisor is 1, so every whole amount from 1 to 5 liters can be done. Every puzzle on this page passes that test.

A strategy that always works

With two jugs, pick one direction and repeat three steps: fill the jug you pour from whenever it is empty, pour it into the other jug, and empty the other jug whenever it is full. Kept up long enough, this passes through every amount the two jugs can measure, so it always finds the answer if there is one. It isn't always the shortest route: going the other way round, from the other jug, can be quicker, so if one direction is taking a while, try the other.

With three jugs, as in puzzles 3 and 5, the extra jug gives you somewhere to park water. Look for a way to make the target as the difference between two things you can measure easily, such as a full big jug less a full small one.

Like planning puzzles? Try the River Crossing Puzzle or the Tower of Hanoi.

Questions

Why can't I pour exactly half a jug?
Because the jugs have no markings, there is no way to know when half has gone. A pour only stops at a point you can be sure of: when the jug you are pouring from is empty, or the one you are pouring into is full.
What counts as a move?
Each fill, each empty and each pour. Moves that change nothing, such as emptying an empty jug, are refused and not counted.
Can every water jug puzzle be solved?
No. With two jugs, only multiples of the jugs' greatest common divisor can be measured, so with 4 and 6 liter jugs you can never get 3 liters. Every puzzle on this page can be solved.
Does the clock start when I press Start?
No, on your first move. You can look at the jugs and plan for as long as you like first.
Why is the water jug problem used in AI courses?
Because it is a small, clear example of state-space search. Each state is the amount in each jug, each fill, empty or pour leads to a new state, and a breadth-first search finds the shortest path to the goal. That is exactly how this page works out the fewest moves for every puzzle.