Cracking The Coding Interview/Q 6.3
You have a five-quart jug, 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 that the jugs are oddly shaped, such that filling up exactly "half"of the jug would be impossible.
- Prepare jug A : 5 quarts, jug B : 3 quarts
- Fill A with 5 quarts, then pour it to B. A will have 2 quarts left
- Empty B, move water from A to B, fill the jug A up : A has 5 quarts, B has 2 quarts.
- move 1 quart of water from A to B : A has 4 quarts, B has 3 quarts.