This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programming Diversions and the fly likes Need solution for below puzzle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Need solution for below puzzle" Watch "Need solution for below puzzle" New topic
Author

Need solution for below puzzle

asdw as
Greenhorn

Joined: May 10, 2012
Posts: 1
Water filling logic Puzzel:

Q : Fill 10 liter container with 3 liters.

10 liter container is empty
18 liter container is empty
29 liter container have 9 liters

we can fill the container from tap but we can't drop the water away(only drop with in containers above).
Myke Enriq
Ranch Hand

Joined: Feb 13, 2012
Posts: 109
Here is my solution , there are a number of steps , I will describe them by the quantities in the containers:

10 | 18 | 29
---------------
0 | 0 | 0
0 | 18 | 0 <- fill the 18 liters recipient
0 | 0 | 18 <- pour the 18 liters recipient into the 29 liters recipient
0 | 18 | 18 <- fill the 18 liters recipient
0 | 11 | 29 <- pour the 18 liters recipient into the 29 liters recipient
10 | 11 | 19 <- fill the 10 liters recipient
3 | 18 | 19 <- pour the 10 liters recipient into the 18 liters one => 3 liters in the first recipient
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
According to the problem statement there were already 9 liters in the 29 liter container.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2339
    
  28

If we can;t drop the water, can we have an elephant drink it? :p Just joking

Here's the solution that I got

10 | 18 | 29
---------------
0 | 0 | 9
10| 0 | 9 <-- add 10 to 10L
0 | 0 | 19 <-- move 10 from 10L to 29L
0 | 18 | 1 <-- move 18 fro 29L to 18L
10 | 8 | 1 --- move 10 from 18L to 10L
0 | 8 | 11 <- move 10 from 10L to 29L
8 | 0 | 11<-- move 8 from 18L to 10L
10 | 0 | 11 <-- add 2 to 10L
0 | 10 | 11 <-- move 10 from 10L to 18L.. now there is 8 empty in 18L
0 | 18 | 3 <-- move 8 from 29L to 18L
3 | 18 | 0 <-- move 3 from 29L to 10L

Done!
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2339
    
  28

Myke Enriq wrote:Here is my solution , there are a number of steps , I will describe them by the quantities in the containers:

10 | 18 | 29
---------------
0 | 0 | 0
0 | 18 | 0 <- fill the 18 liters recipient
0 | 0 | 18 <- pour the 18 liters recipient into the 29 liters recipient
0 | 18 | 18 <- fill the 18 liters recipient
0 | 11 | 29 <- pour the 18 liters recipient into the 29 liters recipient
10 | 11 | 19 <- fill the 10 liters recipient
3 | 18 | 19 <- pour the 10 liters recipient into the 18 liters one => 3 liters in the first recipient


How do you do this

0 | 18 | 18 <- fill the 18 liters recipient
0 | 11 | 29 <- pour the 18 liters recipient into the 29 liters recipient

It should be

0 | 18 | 18 <- fill the 18 liters recipient
0 | 7 | 29 <- pour the 18 liters recipient into the 29 liters recipient
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need solution for below puzzle