“If you have a five-liter and a three-liter bottle and plenty of water, how can you get four liters of water in the five-liter bottle?”
We (all) know this problem, and its natural generalization,
“Given a p-liter and q-liter jug what amounts of water can be obtained?”
My question is different. I would like to know if there's a way to obtain the minimum number of operation to fill one between p and p jug with c liters. Only allowed operation are:
- Overfill a n-liter jug with n-liter
- Empty a jug
- Pour from a jug to another while the first one is empty or the other is full.
Thanks for your attention.
By hand, this is most likely not possible. However, if you use a computer, you can use depth first search to look at all the possible first moves, possible second moves, possible third moves. At some point, you would have found the minimum number of operations required. The downfall to this method is that it has an exponential run-time.