aspose file tools*
The moose likes Programming Diversions and the fly likes puzzle - water jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "puzzle - water jar" Watch "puzzle - water jar" New topic
Author

puzzle - water jar

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830

You have three jars that hold max 19, 13 and 7 liters of water respectively and 20 liters of water in them (not unlimited). I want two jars with 10 liters of water.
Sandip Sankeshwar
Ranch Hand

Joined: Jun 27, 2006
Posts: 210
Dude,I used to solve these puzzled in early 90s.Later these kind of puzzles disappeared from scene somehow.I will give it a try in tea break at 4 PM.
Ryan Maurer
Greenhorn

Joined: Jan 15, 2008
Posts: 5
Here you go. I did it in 14 steps. I don't know if it can be done in fewer.


I will label the 3 jars j1, j2 and j3.
j1 holds 19 litres
j2 holds 13 litres
j3 holds 7 litres

I am starting off by filling j1 full (19 litres) and putting the remaining litre in j2, so I have this makeup

j1 = 19
j2 = 1
j3 = 0

Step 1 Fill j3
j1 = 12
j2 = 1
j3 = 7

Step 2 put j3 in j2
j1 = 12
j2 = 8
j3 = 0

Step 3 fill j3
j1 = 5
j2 = 8
j3 = 7

Step 4 fill j2 with j3
j1 = 5
j2 = 13
j3 = 2

Step 5 put j2 into j1
j1 = 18
j2 = 0
j3 = 2

Step 6 put j3 into j2
j1 = 18
j2 = 2
j3 = 0

Step 7 fill j3
j1 = 11
j2 = 2
j3 = 7

Step 8 put j3 into j2
j1 = 11
j2 = 9
j3 = 0

Step 9 fill j3
j1 = 4
j2 = 9
j3 = 7

Step 10 fill j2 with j3
j1 = 4
j2 = 13
j3 = 3

Step 11 put j2 in j1
j1 = 17
j2 = 0
j3 = 3

Step 12 put j3 into j2
j1 = 17
j2 = 3
j3 = 0

Step 13 fill j3
j1 = 10
j2 = 3
j3 = 7

Step 14 put j3 into j2
j1 = 10
j2 = 10
j3 = 0
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Ryan you rock


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Rajaraman Sriraman
Greenhorn

Joined: Jan 05, 2011
Posts: 3



Am trying to make it to 14 steps
j1 = 19
j2 = 1
j3 = 0

-------------
j1 = 12
j2 = 1
j3 = 7
----------------
put j3 in j2
j1 = 12
j2 = 8
j3 = 0
-----------
fill j3
j1 = 5
j2 = 8
j3 = 7
--------------
fill j2 with j3
j1 = 5
j2 = 13
j3 = 2
-----------------
put j2 into j1
j1 = 18
j2 = 0
j3 = 2
-----------
put j3 into j2
j1 = 18
j2 = 2
j3 = 0
--------------
fill j3
j1 = 11
j2 = 2
j3 = 7
--------------
j3 into j2
j1 = 11
j2 = 9
j3 = 0
--------------
fill j3
j1 = 4
j2 = 9
j3 = 7
--------------
fill j2 with j3
j1 = 4
j2 = 13
j3 = 3
--------------
put j2 in j1
j1 = 17
j2 = 0
j3 = 3
--------------
put j3 into j2
j1 = 17
j2 = 3
j3 = 0
--------------
fill j3
j1 = 10
j2 = 3
j3 = 7
--------------
put j3 into j2
j1 = 10
j2 = 10
j3 = 0
--------------
Rammy Rocks
Rajaraman Sriraman
Greenhorn

Joined: Jan 05, 2011
Posts: 3

j1 = 12
j2 = 1
j3 = 7

Step 2 put j3 in j2
j1 = 12
j2 = 8
j3 = 0

Step 3 fill j3
j1 = 5
j2 = 8
j3 = 7

Step 4 fill j2 with j3
j1 = 5
j2 = 13
j3 = 2

Step 5 put j2 into j1
j1 = 18
j2 = 0
j3 = 2

Step 6 put j3 into j2
j1 = 18
j2 = 2
j3 = 0

Step 7 fill j3
j1 = 11
j2 = 2
j3 = 7

Step 8 put j3 into j2
j1 = 11
j2 = 9
j3 = 0

Step 9 fill j3
j1 = 4
j2 = 9
j3 = 7

Step 10 fill j2 with j3
j1 = 4
j2 = 13
j3 = 3

Step 11 put j2 in j1
j1 = 17
j2 = 0
j3 = 3

Step 12 put j3 into j2
j1 = 17
j2 = 3
j3 = 0

Step 13 fill j3
j1 = 10
j2 = 3
j3 = 7

Step 14 put j3 into j2
j1 = 10
j2 = 10
j3 = 0
Rajaraman Sriraman
Greenhorn

Joined: Jan 05, 2011
Posts: 3
ok
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36468
    
  16
Welcome to JavaRanch and sorry I didn't notice you earlier.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 743
I'm missing something, why not just pour 10 litres in j1, and 10 litres in j2?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36468
    
  16
You have no way of measuring 10. Only 7, 13 and 19.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 988
    
    1
Since this is the Programming Diversions forum, would anyone care to discuss how you'd go about programming a solution to this type of puzzle?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: puzzle - water jar
 
Similar Threads
favorite drink (alcholic or otherwise) put your recipes here
Puzzle asked in interview
how much water do u drink?
Are facts open to interpretation?
Speed camera craziness