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

Home > Logic > Weights and Scales
Water at 76 C (Posted on 2008-06-17) Difficulty: 2 of 5
You only have these three containers, all irregular in their shape (though it doesnt appear in the simplified drawing below), with no marks in them, and all that you know is the capacity of each one.

The 3-liter is empty, the 5-liter is full of 50C water, and the 6-liter is full of 90C water.

                                  |/////|
                      |/////|     |/////|
                      |/////|     |/90/|
          |     |     |/50/|     |/////|
          |     |     |/////|     |/////|
          |     |     |/////|     |/////|
          +-----+     +-----+     +-----+
           3-lit       5-lit       6-lit
With a succession of moves, how do you get some water at 76C? At 75C?

How many different integral temperatures, from 50C to 90C, can you get?

See The Solution Submitted by pcbouhid    
Rating: 4.0000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Step Details for 75 and 76 Comment 5 of 5 |
from    to    V  T    V  T    V  T
3        1    3 90    5 50    3 90
2        3    3 90    2 50    6 70
2        0    3 90    0 50    6 70
3        2    3 90    5 70    1 70
1        3    0 90    5 70    4 85
2        3    0 90    3 70    6 80
3        1    3 80    3 70    3 80
2        3    3 80    0 70    6 75
from    to    V  T    V  T    V  T
3        1    3 90    5 50    3 90
2        3    3 90    2 50    6 70
3        2    3 90    5 62    3 70
3        0    3 90    5 62    0 70
1        3    0 90    5 62    3 90
2        3    0 90    2 62    6 76

DECLARE SUB choose ()
CLEAR , , 26000
DEFDBL A-Z
DIM SHARED cap(3), vol(3), temp(3), lvl
DIM SHARED hBestCt(51 TO 89)
DIM SHARED hBestS(51 TO 89, 20)
DIM SHARED hBestR(51 TO 89, 20)
DIM SHARED hBestV(51 TO 89, 20, 3)
DIM SHARED hBestT(51 TO 89, 20, 3)

cap(1) = 3: vol(1) = 0: temp(1) = 0
cap(2) = 5: vol(2) = 5: temp(2) = 50
cap(3) = 6: vol(3) = 6: temp(3) = 90

lvl = 0

DIM SHARED hSend(20), hRcv(20), hVol(20, 3), hTemp(20, 3)

OPEN "water76.txt" FOR OUTPUT AS #2

choose

FOR i = 51 TO 89
  IF hBestCt(i) > 0 THEN
    FOR j = 0 TO hBestCt(i) - 1
       PRINT USING "# # / "; hBestS(i, j); hBestR(i, j);
    NEXT
    PRINT i
  END IF
NEXT
FOR t = 75 TO 76
  FOR st = 0 TO hBestCt(t) - 1
    PRINT USING "#        #   "; hBestS(t, st); hBestR(t, st);
    FOR i = 1 TO 3
     PRINT USING "## ##   "; hBestV(t, st, i); hBestT(t, st, i);
    NEXT
    PRINT
  NEXT
  PRINT
NEXT


CLOSE

SUB choose
 FOR s = 1 TO 3
  FOR r = 1 TO 3
   IF r <> s THEN
     hSend(lvl) = s: hRcv(lvl) = r
     IF vol(s) > 0 AND vol(r) < cap(r) THEN
       amt = vol(s)
       IF amt > cap(r) - vol(r) THEN amt = cap(r) - vol(r)
       vol(s) = vol(s) - amt
       tempSave = temp(r)
       temp(r) = (temp(r) * vol(r) + temp(s) * amt) / (vol(r) + amt)
       vol(r) = vol(r) + amt
       FOR i = 1 TO 3
        hVol(lvl, i) = vol(i)
        hTemp(lvl, i) = temp(i)
       NEXT

       IF temp(r) - INT(temp(r)) > .9999999000000001# OR temp(r) - INT(temp(r)) < .0000001# AND temp(r) > 50.5 AND temp(r) < 89.5 THEN
         temp(r) = INT(temp(r) + .5)
         FOR i = 0 TO lvl
           PRINT #2, USING "# # / "; hSend(i); hRcv(i);
         NEXT
         PRINT #2, temp(r)
         IF lvl < hBestCt(temp(r)) OR hBestCt(temp(r)) = 0 THEN
           hBestCt(temp(r)) = lvl + 1
           FOR i = 0 TO lvl
            hBestS(temp(r), i) = hSend(i)
            hBestR(temp(r), i) = hRcv(i)
            FOR j = 1 TO 3
             hBestV(temp(r), i, j) = hVol(i, j)
             hBestT(temp(r), i, j) = hTemp(i, j)
            NEXT
           NEXT
         END IF
       END IF

       lvl = lvl + 1
         IF lvl < 11 THEN
           choose
         END IF
       lvl = lvl - 1

       vol(s) = vol(s) + amt
       temp(r) = tempSave
       vol(r) = vol(r) - amt
     END IF
   END IF
  NEXT
 NEXT
 FOR s = 1 TO 3
   IF vol(s) > 0 THEN
     volSave = vol(s)
     vol(s) = 0
     hSend(lvl) = s: hRcv(lvl) = 0
     FOR j = 1 TO 3
       hVol(lvl, j) = vol(j)
       hTemp(lvl, j) = temp(j)
     NEXT
     lvl = lvl + 1
       IF lvl < 10 THEN
           choose
       END IF
     lvl = lvl - 1
     vol(s) = volSave
   END IF
 NEXT
END SUB

 


  Posted by Charlie on 2008-06-18 11:05:44
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 (1)
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