All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > General
The 5 jugs (Posted on 2005-08-18) Difficulty: 2 of 5
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...)

See The Solution Submitted by pcbouhid    
Rating: 2.2500 (4 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re: Solution | Comment 5 of 36 |
(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
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information