File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programming Diversions and the fly likes How to solve this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "How to solve this" Watch "How to solve this" New topic

How to solve this

vanlalhmangaiha khiangte
Ranch Hand

Joined: Sep 11, 2006
Posts: 170
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 ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

You can't link to your local machine, you need to upload the image somewhere first.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

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?

Software Surgeon
vanlalhmangaiha khiangte
Ranch Hand

Joined: Sep 11, 2006
Posts: 170
Have no clue ...
Just trying trial and error method ...
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
Jug1----->Jug1(19 litres)
Jug2-move->Jug2(13 litres)





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.


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 ]
I agree. Here's the link:
subject: How to solve this
It's not a secret anymore!