File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

puzzle - water jar

 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 210
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan you rock
 
Rajaraman Sriraman
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch and sorry I didn't notice you earlier.
 
colin shuker
Ranch Hand
Posts: 750
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm missing something, why not just pour 10 litres in j1, and 10 litres in j2?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have no way of measuring 10. Only 7, 13 and 19.
 
Ryan McGuire
Ranch Hand
Posts: 1048
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic