Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

puzzle - water jar

 
Ranch Hand
Posts: 3850
  • 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.

 
Ranch Hand
Posts: 210
  • 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.
 
Greenhorn
Posts: 5
  • Likes 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
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan you rock
 
Greenhorn
Posts: 3
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok
 
Marshal
Posts: 69403
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch and sorry I didn't notice you earlier.
 
Ranch Hand
Posts: 750
  • 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
Marshal
Posts: 69403
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have no way of measuring 10. Only 7, 13 and 19.
 
Rancher
Posts: 1196
22
  • 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?

 
Do you want ants? Because that's how you get ants. And a tiny ads:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic