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.)
Solution re(2): Solution (spoilers present--computer solutions) | Comment 6 of 36 |
(In reply to re: Solution by Charlie)

Actually that previous version only checked to 10 steps deep.

This one checks to 12 steps.  Some of the 11-step solutions found are as follows (sequence of capacities: 3, 4, 7, 6, 5):

 3  0  7  0  5 
 0  3  7  0  5
 0  3  7  5  0
 0  3  6  6  0
 0  2  7  6  0
 0  2  7  1  5
 3  2  7  1  2
 3  2  7  3  0
 0  2  7  3  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 0  3  7  5  0
 0  3  6  6  0
 0  3  6  1  5
 0  2  7  1  5
 3  2  7  1  2
 3  2  7  3  0
 0  2  7  3  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 0  3  7  5  0
 0  3  6  6  0
 0  3  6  1  5
 3  3  6  1  2
 3  2  7  1  2
 3  2  7  3  0
 0  2  7  3  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 0  3  7  5  0
 0  3  6  6  0
 0  3  6  1  5
 3  3  6  1  2
 3  3  6  3  0
 0  3  6  3  3
 0  2  7  3  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 0  3  7  5  0
 0  3  6  6  0
 0  3  6  1  5
 3  3  6  1  2
 3  3  6  3  0
 3  2  7  3  0
 0  2  7  3  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 2  4  7  0  2
 2  4  1  6  2
 2  4  1  3  5
 2  4  0  4  5
 2  0  4  4  5
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 2  4  7  0  2
 2  4  1  6  2
 2  4  1  3  5
 2  4  0  4  5
 2  4  0  6  3
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 3  3  1  6  2
 2  4  1  6  2
 2  4  1  3  5
 2  4  0  4  5
 2  0  4  4  5
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 3  3  1  6  2
 2  4  1  6  2
 2  4  1  3  5
 2  4  0  4  5
 2  4  0  6  3
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 3  3  1  6  2
 3  3  1  3  5
 2  4  1  3  5
 2  4  0  4  5
 2  0  4  4  5
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 3  3  1  6  2
 3  3  1  3  5
 2  4  1  3  5
 2  4  0  4  5
 2  4  0  6  3
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 3  3  1  6  2
 3  3  1  3  5
 3  3  0  4  5
 2  4  0  4  5
 2  0  4  4  5
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 3  3  1  6  2
 3  3  1  3  5
 3  3  0  4  5
 2  4  0  4  5
 2  4  0  6  3
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3
 3  0  7  0  5 
 0  3  7  0  5
 3  3  7  0  2
 3  3  1  6  2
 3  3  1  3  5
 3  3  0  4  5
 3  3  0  6  3
 2  4  0  6  3
 2  0  4  6  3
 2  0  7  3  3
 2  4  3  3  3
 3  3  3  3  3

The new version:

DECLARE SUB try (lvl!)
DIM SHARED amt(3 TO 7)
DIM SHARED hist(15, 3 TO 7)

OPEN "fivejugs.txt" FOR OUTPUT AS #2

amt(3) = 3
amt(5) = 5
amt(7) = 7

try 1

CLOSE

END

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
      j2 = j
      IF j = 5 THEN j2 = 7
      IF j = 7 THEN j2 = 5
       PRINT hist(i, j2);
       PRINT #2, hist(i, j2);
     NEXT
     PRINT
     PRINT #2,
   NEXT
   PRINT
   PRINT #2,
 ELSE
  IF lvl < 13 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 16:17:27
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 (15)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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