Free logic puzzles to play and print

Jugs Puzzle: Water Jug Puzzle and Solver

Fill, empty and pour until one jug holds the target amount. Stuck? Ask for a hint or watch the shortest solution.

The jugs puzzle on this page is a free, interactive water jug puzzle and solver that runs in your browser. You fill, empty and pour water between jugs of set sizes until one jug holds an exact amount, such as 4 litres from a 3-litre and a 5-litre jug. There is no sign-up, and nothing is uploaded.

The tool offers two kinds of puzzle. In tap and drain mode you use 2 or 3 jugs, all empty at the start, with unlimited water from a tap. The goal can be one jug holding a set amount, or all the jugs together holding an amount. In fixed water mode you get exactly 3 jugs with given starting amounts, and the only move is pouring. The goal there is for every jug to hold a given amount, such as 4, 4 and 0.

You can also build your own puzzle.

How to use the Water Jug Puzzle

  1. Pick an example puzzle, such as “3 and 5 jugs: measure 4”. To build your own, choose “Your own puzzle” and set the jug sizes, the number of jugs, the type and the goal.
  2. In tap and drain mode, press a jug’s Fill button to fill it from the tap. Fixed water mode has no tap, so you won’t see this step there.
  3. Press a jug’s Empty button to pour all of its water away.
  4. To pour from one jug into another, press the source jug’s Pour button, or drag one jug onto another, or tap one jug and then tap another. Each pour continues until the source is empty or the target is full.
  5. Watch the move list and the move counter. Each fill, empty or pour counts as one move.
  6. If you get stuck, press Hint. Use Undo to step back, or Reset to start the puzzle again.
  7. When the goal is reached, the tool compares your number of moves with the minimum.

If you want the answer, press Show solution. It gives a shortest solution either step by step with Next step, or all at once with Play all. Try the puzzle yourself first, so you can compare your moves with the shortest route.

How do you get 4 litres with a 3 and a 5 litre jug?

Fill the 5-litre jug, then pour from it into the 3-litre jug until the 3 is full. This leaves exactly 2 litres in the 5-litre jug. Empty the 3-litre jug, pour the 2 litres into it, refill the 5-litre jug, and pour from it into the 3-litre jug until the 3 is full. The 1 litre it needs leaves exactly 4 litres in the 5-litre jug.

The steps, using the tool’s shortest solution, are:

  1. Fill the 5.
  2. Pour the 5 into the 3 (the 3 is now full, the 5 holds 2).
  3. Empty the 3.
  4. Pour the 2 left in the 5 into the 3.
  5. Fill the 5.
  6. Pour the 5 into the 3 until it is full, which leaves 4 in the 5.

This puzzle is the riddle from the 1995 film Die Hard with a Vengeance. The site measures in litres, but the maths is the same for gallons.

How do you know if a water jug puzzle can be solved?

A tap-mode puzzle with a goal of one jug holding an amount T can be solved when T is a multiple of the greatest common divisor (gcd) of the jug sizes, and T is no bigger than the largest jug. With two jugs, these two conditions are enough. This follows from Bézout’s identity, which says that combinations of the two jug sizes can produce their gcd.

For example, a 3-litre and a 5-litre jug have a gcd of 1, so every amount from 1 to 5 is possible. A 2-litre and a 4-litre jug have a gcd of 2, so they can only reach 2 and 4 litres. The 3-litre goal is impossible with them.

For a goal of the total water in all the jugs, T must be a multiple of the gcd and no more than the sum of the jug sizes. In fixed water mode, the goal amounts must add up to the starting water. Even then, some splits are impossible, and the solver detects these. If your custom puzzle has no solution, the tool explains why: the amount is not a multiple of the gcd, it is too big, the totals don’t match, or it can’t be reached.

Frequently asked questions

How do you split 8 litres into two 4s with 8, 5 and 3 litre jugs?

Start with the 8 full and the other two empty. Use seven pours in this order: 8 into 5, 5 into 3, 3 into 8, 5 into 3, 8 into 5, 5 into 3, 3 into 8. The 8-litre jug and the 5-litre jug each end with 4 litres.

Does the water jug puzzle work on a phone or tablet?

Yes. It runs in the phone’s browser with nothing to install. Every jug has its own Fill, Empty and Pour buttons, and you can also pour by tapping one jug and then another.

Do I have to measure the water by eye?

No. A pour always goes until the source jug is empty or the target jug is full, so every amount comes from the jug sizes themselves. Each fill, empty or pour counts as one move.

What does “fixed water: pouring only” mean?

It is the puzzle type with exactly 3 jugs, starting amounts already filled in, and no tap or drain. The only move you can make is pouring. The goal is for every jug to hold a given amount, such as 4, 4 and 0.

Is the 3 and 5 litre puzzle the same as the 3 and 5 gallon riddle?

Yes, the maths is the same. The film riddle used gallons, while the tool uses litres. The solution steps are the same whichever unit you use.