You have five different jugs, without any marks at all, with capacities of 3, 4, 5, 6 and 7 litres. Initially, the
3,
5 and
7-jugs are completely filled with liquid (so we have 15 litres of the liquid; in the diagram below, an "x" stands for 1 litre) and the other two are empty. The jugs are arranged in the circular manner shown below, which can't be changed:
| |
+-+ +-+
| o o |
| o o |
+-----+
| | | |
+-+ +-+ +---+ +---+
| x | | x x x x |
| x x | | x x x |
+-----+ +---------+
| | | |
+--+ +--+ +--+ +--+
| x x x | | o o o |
| x x | | o o o |
+-------+ +-------+
The goal is to achieve 3 litres in each of the 5 jugs, only by pouring liquid from one jug into an
adjacent one. (That is, at any time, you can pour liquid from the 3-jug only into the 4-jug or to the 5-jug; or from the 7-jug only into the 4-jug or to the 6-jug, etc...)
(In reply to
Solution by Hugo)
In
3 0 7 0 5
0 3 7 0 5
3 3 7 0 2
3 3 7 2 0
3 3 3 6 0
3 3 3 0 6
3 3 0 3 6
3 0 3 3 6
0 3 3 3 6
3 3 3 3 3
the last column represents, by the first line, the jug with capacity of 5 liters, but in several of the steps it holds 6 liters. This is not possible.
The following program checks to a level of 11 steps and finds no solution:
DECLARE SUB try (lvl!)
DIM SHARED amt(3 TO 7)
DIM SHARED hist(11, 3 TO 7)
amt(3) = 3
amt(5) = 5
amt(7) = 7
try 1
SUB try (lvl)
good = 1
FOR jug = 3 TO 7
hist(lvl, jug) = amt(jug)
IF amt(jug) <> 3 THEN good = 0
NEXT
IF good THEN
FOR i = 1 TO lvl
FOR j = 3 TO 7
PRINT hist(i, j);
NEXT
PRINT
NEXT
PRINT
ELSE
IF lvl < 11 THEN
FOR j1 = 3 TO 7
IF j1 < 7 THEN j2 = j1 + 1: ELSE j2 = 4
IF j1 = 4 THEN j2 = 7
IF amt(j1) > 0 AND amt(j2) < j2 THEN
IF amt(j1) > j2 - amt(j2) THEN
trfr = j2 - amt(j2)
ELSE
trfr = amt(j1)
END IF
amt(j2) = amt(j2) + trfr
amt(j1) = amt(j1) - trfr
try lvl + 1
amt(j2) = amt(j2) - trfr
amt(j1) = amt(j1) + trfr
END IF
IF j1 > 3 THEN j2 = j1 - 1: ELSE j2 = 5
IF j1 = 5 THEN j2 = 3
IF amt(j1) > 0 AND amt(j2) < j2 THEN
IF amt(j1) > j2 - amt(j2) THEN
trfr = j2 - amt(j2)
ELSE
trfr = amt(j1)
END IF
amt(j2) = amt(j2) + trfr
amt(j1) = amt(j1) - trfr
try lvl + 1
amt(j2) = amt(j2) - trfr
amt(j1) = amt(j1) + trfr
END IF
NEXT
END IF
END IF
END SUB
|
Posted by Charlie
on 2005-08-18 15:35:08 |