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
• Ron McLeod
• Bear Bibeault
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Junilu Lacar
• Henry Wong
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Jj Roberts
• Tim Holloway
• Piet Souris
Bartenders:
• Himai Minh
• Carey Brown
• salvin francis

# puzzle - water jar

Ranch Hand
Posts: 3851

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
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
• 1
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
Ryan you rock

Greenhorn
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
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
Posts: 3
ok

Marshal
Posts: 71047
291
Welcome to JavaRanch and sorry I didn't notice you earlier.

Ranch Hand
Posts: 750
I'm missing something, why not just pour 10 litres in j1, and 10 litres in j2?

Campbell Ritchie
Marshal
Posts: 71047
291
You have no way of measuring 10. Only 7, 13 and 19.

Bartender
Posts: 1201
22
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?

 Don't touch me. And dont' touch this tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton