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.
| Puzzle | Jugs (liters) | Measure | Fewest moves |
|---|---|---|---|
| 1 | 3 and 5 | 4 liters | 6 |
| 2 | 4 and 9 | 6 liters | 8 |
| 3 | 5, 7 and 12 | 11 liters | 9 |
| 4 | 8 and 13 | 6 liters | 10 |
| 5 | 5, 9 and 14 | 7 liters | 12 |
| 6 | 7 and 11 | 9 liters | 16 |
| 7 | 9 and 13 | 11 liters | 20 |
| 8 | 11 and 15 | 13 liters | 24 |
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:
- Fill the 5 liter jug. The jugs now hold 0 and 5 liters.
- Pour the 5 liter jug into the 3 liter jug. The jugs now hold 3 and 2 liters.
- Empty the 3 liter jug. The jugs now hold 0 and 2 liters.
- Pour the 5 liter jug into the 3 liter jug. The jugs now hold 2 and 0 liters.
- Fill the 5 liter jug. The jugs now hold 2 and 5 liters.
- 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) | Perfect | Excellent | Good | Fair | Keep trying |
|---|---|---|---|---|---|
| 1 | 6 | – | 7–8 | 9–10 | 11+ |
| 2 | 8 | 9 | 10 | 11–14 | 15+ |
| 3 | 9 | 10 | 11–12 | 13–16 | 17+ |
| 4 | 10 | 11 | 12–13 | 14–18 | 19+ |
| 5 | 12 | 13 | 14–16 | 17–21 | 22+ |
| 6 | 16 | 17–18 | 19–21 | 22–28 | 29+ |
| 7 | 20 | 21–23 | 24–27 | 28–36 | 37+ |
| 8 | 24 | 25–27 | 28–32 | 33–43 | 44+ |
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)
- Pour the 8 liter jug into the 5 liter jug. The jugs now hold 3, 5, 0 liters.
- Pour the 5 liter jug into the 3 liter jug. The jugs now hold 3, 2, 3 liters.
- Pour the 3 liter jug into the 8 liter jug. The jugs now hold 6, 2, 0 liters.
- Pour the 5 liter jug into the 3 liter jug. The jugs now hold 6, 0, 2 liters.
- Pour the 8 liter jug into the 5 liter jug. The jugs now hold 1, 5, 2 liters.
- Pour the 5 liter jug into the 3 liter jug. The jugs now hold 1, 4, 3 liters.
- 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)
- Pour the 10 liter jug into the 7 liter jug. The jugs now hold 3, 7, 0 liters.
- Pour the 7 liter jug into the 3 liter jug. The jugs now hold 3, 4, 3 liters.
- Pour the 3 liter jug into the 10 liter jug. The jugs now hold 6, 4, 0 liters.
- Pour the 7 liter jug into the 3 liter jug. The jugs now hold 6, 1, 3 liters.
- Pour the 3 liter jug into the 10 liter jug. The jugs now hold 9, 1, 0 liters.
- Pour the 7 liter jug into the 3 liter jug. The jugs now hold 9, 0, 1 liters.
- Pour the 10 liter jug into the 7 liter jug. The jugs now hold 2, 7, 1 liters.
- Pour the 7 liter jug into the 3 liter jug. The jugs now hold 2, 5, 3 liters.
- 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.