Sunday, July 31, 2011

Solution to 4 quarts of Water puzzle

Question: http://good-interview-puzzles.blogspot.com/2011/07/4-quarts-of-water.html


This question is very simple actually. Since we can’t hold 4 quarts in the 3 quart pail, we have to look to filling up the 5 quart pail with exactly 4 quarts. Lets count the steps as we move along

1. Fill 3 quart pail ( 5p – 0, 3p – 3)
2. Transfer to 5 quart pail (5p – 3, 3p – 0)
3. Fill 3 quart pail ( 5p – 3, 3p – 3)
4. Transfer to 5 quart pail (5p – 5, 3p – 1)
5. Empty 5 quart pail (5p – 0, 3p – 1)
6. Transfer to 5 quart pail (5p – 1, 3p – 0)
7. Fill 3 quart pail ( 5p – 1, 3p – 3)
8. Transfer to 5 quart pail (5p – 4, 3p – 0) We are done!!!

That was easy right. Now for those who are mathematical and need everything solved in terms of a formula, here comes a little more mathematical solution.

Now the general steps are to fill up the 3 quart pail and keep transferring to the 5 quart pail (empty if full) until we hit 4 quarts. Therefore, the total amount of water we filled in the 3 quart pail must be equal to 4 more than a multiple of 5 (since we discard 5 quarts of water at a time). From this, we can derive this formula.
5n + 4 = 3m, where n and m are arbitrary positive integers
n represents the number of times we had to empty the 5 quart pail and m represents the number of times we had to fill up the 3 quart pail.

Now all we have to do is solve for the lowest set of positive integer solutions for {n,m}. {1, 3} is the lowest set. Some of the other solutions are {4, 8}, {7, 13}, {10, 18} and so on.

No comments:

Post a Comment