This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to solve this

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three jugs :-
1) 19 litres Empty JUG
2) 13 litres JUG full of water
3) 7 litres JUG full of water

Total - 20 litres of water are there ...

I want 10 litres of water in the two jugs 1 and 2 ...

Tried to solve it but not able to get it ...
[ August 07, 2008: Message edited by: vanlalhmangaiha khiangte ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't link to your local machine, you need to upload the image somewhere first.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/SearchFirst

http://www.google.com/search?q=three+jugs+19+13+7
 
Ranch Hand
Posts: 376
Scala Monad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't check the solution yet (I don't want to spoil it), but since is a common type of problem and we're talking about programming, let me put a spin on it: what algorithm would you use to solve the problem?
 
vanlalhmangaiha khiangte
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have no clue ...
Just trying trial and error method ...
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jug1----->Jug1(19 litres)
Jug2-move->Jug2(13 litres)
Jug3----->Jug3(7litres)


0----->13----->13--X-->6----->6----->
13--X-->0---->7----->7----->13--X-->
7----->7--X-->0----->7--X-->1----->

19----->19--X-->12----->12--X-->5----->
0----->1----->1----->8----->8----->
1--X-->0----->7--X-->0----->7--X-->

5----->18----->18--X-->11----->11--X-->
13--X-->0----->2----->2----->9----->
2----->2--X-->0----->7--X-->0----->

4----->4----->17----->17--X-->10----->10
9----->13--X-->0----->3----->3----->10
7--X-->3----->3--X-->0----->7--X-->0

The X is which jug poured
So...what kind of pattern can we discern from this?
To me, it looks like we move from the lowest to the middle (until it will fill up the middle)
then from middle to biggest until it will over flow then we dump what we can into the small one and rinse repeat.

So

That should do it I think. Have no idea as to syntax or anything. It's all notepad psuedo'd
It's a really slow day at work...if only someone out there was bored enough to actually check my logic. >.>
[ August 18, 2008: Message edited by: Paul Yule ]
 
It's a beautiful day in this neighborhood - Fred Rogers. 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
    Bookmark Topic Watch Topic
  • New Topic