water jug problem

100 Views Asked by At

The original version of water jug problem is that we have two empty jugs and an infinite source of water and the goal is to find a way to reach a state so that one of the jugs contains a specific amount of water. for example we have two jugs of 20 and 30 liter volume. and the goal is to reach a state that the 20 liter jug contains 10 liter of water. and the problem has an answer if and only if the GCD of volumes is divisible by the wished amount of water in goal state.

But I came up with another version of this problem which in the goal state , instead of specifying the water of one jug , we specify the amount of water in both jugs. for example in goal state we wish both of the jugs contain 20 liter of water.

What is the condition for having answer in second version?

1

There are 1 best solutions below

0
On

Under the usual rules for problems of this sort, the only moves available to you are:

  • Fill one of the jugs from the reservoir;
  • Empty one of the jugs into the reservoir;
  • Empty one of the jugs into the other; or
  • Fill one of the jugs from the other.

If that's the case, then after each move, either one of the jugs must be full or one of the jugs must be empty. So, unless the specification of your goal state includes one of those two criteria, it is unachievable.