Tuesday, March 25, 2014

Get 4qt of water using a 5qt jug and a 3qt jug

Problem:

You have a five quart jug and a three quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water?
NOTE: The jugs are oddly shaped, such that filling up exactly ‘half’ of the jug would be impossible.

Solution:

I first thought we can come up with 2qt water by filling up the 5qt jug and pouring 3qt water to the 3qt jug. We then have 2qt of water left in the 5qt jug. We can pour it to out and repeat the process to get another 2qt. Then I think the question does not allow you to use another jug to hold the water, i.e., all of the process should be done using only the two jugs. Therefore we have the following method:

5qt jug 3qt jug
5 0
2 3
2 0
0 2
5 2
4 3
4 0
“Many brain teasers have a math / CS root to them—this is one of them! Note that as long as the two jug sizes are relatively prime (i.e., have no common prime factors), you can find a pour sequence for any value between 1 and the sum of the jug sizes.”
Wow really?! Let’s try from 1 to 5+3=8.
  1. After we get 4qt in the 5qt jug, we pour it to the 3qt jug until filling up, then we end up with 1qt of water in the 5qt jug.
  2. Fill up the 5qt jug and pour 3qt to the 3qt jug.
  3. Fill up the 3qt jug.
  4. Covered above.
  5. Fill up the 5qt jug.
  6. We can never get 6qt of water with these two jugs. But we can definitely get 6 with a separate jug. We already have 1 and 5.
  7. 2 + 4.
  8. 3 + 5.
Therefore, it should be “you can find a pour sequence for any value between 1 and the maximum volume of the two jugs, using only these two jugs”.

0 comments:

Post a Comment