Logic problem 15 of 30

Water jugs

  • Logic
  • Medium

You have a 3-litre jug, a 5-litre jug and a tap. Neither jug has any markings. How do you measure exactly 4 litres?

Show hint

Filling the 5-litre jug and pouring into the 3-litre jug leaves exactly 2 litres behind.

Show solution
  1. Fill the 5 L jug. (5 L jug: 5, 3 L jug: 0)
  2. Pour into the 3 L jug until it is full. (2, 3)
  3. Empty the 3 L jug. (2, 0)
  4. Pour the 2 litres into the 3 L jug. (0, 2)
  5. Fill the 5 L jug. (5, 2)
  6. Top up the 3 L jug, which takes 1 litre. (4, 3)

The 5 L jug now holds 4 litres. A program can find this by breadth-first search over (big, small) states, which also proves 6 steps is the minimum.

Want a problem like this every day? See today's problem and keep a streak going.