Learn / Library / Brainteasers
Paint cans on a ledge
A painter has an empty -litre can and an empty -litre can, with an unlimited tap and a drain. One operation is one of: fill a can to the brim at the tap, empty a can completely down the drain, or pour from one can into the other until the source is empty or the target is full. There are no markings on the cans. What is the minimum number of operations after which one of the cans holds exactly litres?
Checking an answer needs JavaScript. The hint and the solution open without it.
Hint
Write the contents as a pair (small, big) and search level by level; only fills, empties and pours are allowed.
Solution
- Fill the big can (), pour into the small can (), empty the small can () and pour again (): the pair is (, ), so only litre is left in the big can.
- Empty the small can () and pour the litre across (), giving the pair (, ).
- Fill the big can () and pour into the small can, which has room for litres ().
- The big can then holds exactly litres, and a search of all shorter sequences finds nothing that reaches .
- So the minimum number of operations is .
Answer: