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.
/* Initially 3quart jug and 5quart jug are empty */
1. Fill 5 quart jug
/* Now 3quart jug is empty and 5quart jug is full */
2. Pour water from 5quart jug into empty 3quart jug.
/* Now 3quart jug is full and 5quart jug has 2quart remaining in it */
3. Now empty the 3quart jug.
/* Now 3quart jug is empty and 5quart jug has 2quart remaining in it
*/
4. Transfer all water from 5quart jug to 3 quart jug
/* Now 5quart jug is empty and 3quart jug has 2quart remaining in it
*/
5. Now again fill 5 quart jug.
/* Now 5quart jug is full and 3quart jug has 2quart remaining in it
*/
6. Pour water from 5quart jug to 3quart jug till it gets filled up.
/* Now 5quart jug has 4quarts ( which s wat we need :) ) and 3quart
jug is full (which is unnecessary) */
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.
/* Initially 3quart jug and 5quart jug are empty */
1. Fill 5 quart jug
/* Now 3quart jug is empty and 5quart jug is full */
2. Pour water from 5quart jug into empty 3quart jug.
/* Now 3quart jug is full and 5quart jug has 2quart remaining in it */
3. Now empty the 3quart jug.
/* Now 3quart jug is empty and 5quart jug has 2quart remaining in it
*/
4. Transfer all water from 5quart jug to 3 quart jug
/* Now 5quart jug is empty and 3quart jug has 2quart remaining in it
*/
5. Now again fill 5 quart jug.
/* Now 5quart jug is full and 3quart jug has 2quart remaining in it
*/
6. Pour water from 5quart jug to 3quart jug till it gets filled up.
/* Now 5quart jug has 4quarts ( which s wat we need :) ) and 3quart
jug is full (which is unnecessary) */
No comments:
Post a Comment