Water Jug Puzzles

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Water-Jug Puzzles

Water-Jug Puzzles

In the water-jug puzzle we are given a 4-liter jug, and a 7-liter jug.
Initially, both jugs are empty. Either jug can be filled with water from a
tap, and we can discard water from either jug down a drain. Water may be
poured from one jug into the other. There is no additional measuring
device. We want to find a set of operations that will leave precisely x liters
of water in either one of the jugs.
i. Set up a state-space search formulation of the water jug puzzle:
a) Given the initial iconic state description as a data structure.
b) Give a goal condition on states as some test on data structures.
c) Name the operators on states and give precise descriptions of what
each operator does to a state description.
ii. Find whether the goals x = {1, 2, 3, 4, 5, 6, 7} can be accomplished in
8 or fewer steps.
Hint: Use breadth-first search.

Dr. Zoran Duric () Water Jug Puzzles 1/ 6 January 29, 2013 1/6
Water-Jug Puzzles

Water-Jug Puzzle

a) (A B) // A is the amount in the 4-liter jug


// B in the 7-liter jug
b) (A == x) or (B == x)

c) FA: (4 B),
FB: (A 7)
EA: (0 B),
EB: (A 0)

PAB: if ((A+B)<= 7) then (0 A+B)


else (A+B-7 7)
PBA: if ((A+B)<=4) then (A+B 0)
else (4 A+B-4)

Dr. Zoran Duric () Water Jug Puzzles 2/ 6 January 29, 2013 2/6
Water-Jug Puzzles

Water-Jug Puzzle Solution

Dr. Zoran Duric () Water Jug Puzzles 3/ 6 January 29, 2013 3/6
Water-Jug Puzzles

Bouncing Ball Solution

Graphing the paths of balls bouncing inside rhomboidal tables


0 1 2 3 4 5 6 7 8 9 10 11
7 7
6 6

5 5

4 4

3 3

2 2

1 1

0 0
0 1 2 3 4 5 6 7 8 9 10 11

11ïPINT VESSEL 11 4 4 0 11 8 8 1 1 0 11 5 5 0 11 9 9 2

7ïPINT VESSEL 0 7 0 4 4 7 0 7 0 1 1 7 0 5 5 7 0 7

Dr. Zoran Duric () Water Jug Puzzles 4/ 6 January 29, 2013 4/6
Water-Jug Puzzles

7-pint and 11-pint jugs. Readings on the horizontal axis represent the
amount of water in the 11-pint vessel at any time and readings on the
vertical axis tell how much water is in the 7-pint vessel.

The angle of vertical to the horizontal side is 60◦ .

To use this graph, imagine a ball at point 0 in the lower left corner. It
travels to the right along the base of the rhomboid until it strikes the
right-hand cushion at a point labeled 11 on the base line: the 11-pint
vessel has been filled and the 7-pint jug remains empty. After bouncing off
the right-hand cushion the ball travels up to the left until it hits the top
cushion at point 4 on the horizontal coordinate and on the seventh line on
the side coordinate. This plot indicates that 7 pints have been transferred
from the 11-pint vessel to the 7-pint vessel, leaving 4 pints in the larger
vessel.

Dr. Zoran Duric () Water Jug Puzzles 5/ 6 January 29, 2013 5/6
Water-Jug Puzzles

If you continue to follow the bouncing ball until it strikes a point marked
2, keeping a record of each step, you will obtain the 18-step answer shown
below the graph. This is actually not the shortest answer. An alternative
procedure is to begin by filling the 7-pint vessel. This is graphed by
starting the ball at the 0 point and rolling it up along the table’s left side.
If you trace the ball’s path until it strikes a 2 point, keeping a record of
the steps, you will find that this ball computer bounces out a solution in
14 steps—the minimum.

Dr. Zoran Duric () Water Jug Puzzles 6/ 6 January 29, 2013 6/6

You might also like