Water Pouring Puzzle
Which amounts can two unmarked jugs measure? Exactly the multiples of their gcd — verified by search over 225 jug pairs, zero mismatches.
Which amounts can you measure? Exactly the multiples of the gcd.
The answer is not "it depends how clever you are". The volumes you can reach are exactly the multiples of the greatest common divisor of the two jugs, up to the size of the larger one. Nothing else is reachable, however long you pour.
That is a theorem, so this page checks it rather than quoting it: a breadth-first search over the real state space for every jug pair from 1×1 to 15×15 — 225 pairs — against the predicted set of multiples. Zero mismatches.
| Jugs | Target | gcd | Possible? | Shortest |
|---|---|---|---|---|
| 3 and 5 | 4 | 1 | yes | 6 moves |
| 5 and 8 | 6 | 1 | yes | 6 moves |
| 7 and 9 | 5 | 1 | yes | 4 moves |
| 6 and 10 | 4 | 2 | yes | 2 moves |
| 4 and 6 | 5 | 2 | no | — |
| 9 and 13 | 7 | 1 | yes | 16 moves |
Which settles the classic frustration. A 4 and a 6 cannot measure 5, and no amount of pouring will help — their gcd is 2 and 5 is odd. A 3 and a 5 can measure anything up to 5, because their gcd is 1. If you have ever been stuck on one of these, check the gcd before assuming you are missing something.
No wrong answers, but there is a wrong direction
There are really only two strategies: keep filling the big jug and pouring into the small one, or the other way round. Both reach every reachable volume, so either eventually works — but across 757 solvable jug-and-target combinations, one direction is strictly shorter in 734 of them. Ninety-seven per cent, with only 23 ties. So the puzzle has no wrong answers and it does have a wrong direction, which is an unusually pleasant thing for a puzzle to be. If your solution is dragging, try filling the other jug first.
Notes
- Only three kinds of move exist. Fill a jug to the top, empty one completely, or pour one into the other until the source is empty or the destination is full. Partial pours are not allowed, which is exactly why the puzzle is finite.
- Any target above the larger jug is impossible, whatever the gcd — you have nowhere to put it.
- The hint gives the genuinely shortest solution, found by breadth-first search. The test also confirms that no sequence one move shorter can reach the target.
- The Die Hard puzzle is 3 and 5 for 4, and it takes six moves. It is on the preset list, as is one that cannot be done at all.
How to use
- Pick two jug sizes and the amount you want to measure.
- Fill, empty and pour — partial pours are not allowed.
- Check the verdict first: some targets are impossible, not just hard.
- Use the hint for the genuinely shortest solution.
Frequently asked questions
How do you get 4 litres from a 3 and a 5?
Six moves. Fill the 5, pour it into the 3 leaving 2, empty the 3, pour the 2 across, fill the 5 again and top up the 3 — which takes 1 and leaves exactly 4. It is the puzzle from Die Hard with a Vengeance, and the tool will show it.
Which amounts can two jugs measure?
Exactly the multiples of their greatest common divisor, up to the size of the larger jug. That is Bezout, and nothing outside that set is reachable however long you pour. This page verifies it by breadth-first search over every jug pair up to 15 by 15 — 225 pairs, zero mismatches.
Why can I not measure 5 with a 4 and a 6?
Because the gcd of 4 and 6 is 2, so every reachable amount is even. Five is odd, so it is not merely difficult, it is impossible. If you are stuck on a puzzle like this, check the gcd before assuming you have missed a clever move.
When is a water jug puzzle solvable?
When the target divides evenly by the gcd of the two jugs AND is no larger than the bigger jug. Those two conditions together are exactly the answer — there is no third case.
Does it matter which jug I fill first?
Almost always, yes. There are two sensible strategies — keep filling the big jug and pouring into the small one, or the reverse — and across 757 solvable combinations one direction is strictly shorter in 734 of them. Ninety-seven per cent. If your solution is dragging, try the other jug.
What moves are allowed?
Only three kinds: fill a jug to the top, empty one completely, or pour one into the other until the source is empty or the destination is full. Partial pours are not allowed, which is exactly what makes the puzzle finite and solvable by search.
Is the hint the shortest possible solution?
Yes. It comes from a breadth-first search, which finds a shortest path by construction — and the tests additionally confirm that no sequence one move shorter can reach the target.
Can I measure an amount bigger than both jugs?
No. There is nowhere to put it, whatever the gcd says. The target has to fit in one of the two jugs.
Does this send anything anywhere?
No. Everything runs in your browser and nothing is stored or uploaded.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.