wood burning stoves 2.0*
The moose likes Programming Diversions and the fly likes Sharing the peanut oil Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Sharing the peanut oil" Watch "Sharing the peanut oil" New topic
Author

Sharing the peanut oil

Rakesh Joshi
Ranch Hand

Joined: Feb 24, 2006
Posts: 218
Mary has a full 8-quart container (Container A) of peanut oil. She wants to share half of the oil with her sister. She has another 2 empty containers (B and C) with the capacities: 5 quarts and 3 quarts. Can you, without weighing the containers, put 4 quarts of oil in container B with the least number of steps for her sister?


Life is a Game play it.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

One quick solution -

(1) Take out 3 quarts of oil from A into C. A has 5 quarts left now.
(2) Transfer 3 quarts from C to B. Now B has 3, A has 5 and C has zero.
(3) Take out Another 3 quarts from A into C. A=2, B=3, and C=3 now.
(4) Transfer from C to B only till B is full. A=2, B=5 and C=1 ((3-2)) now.
(5) Empty B in A now. A=7, B=0 and C=1;
(6) Put C in B. A=7, B=1 and C=0;
(7) Take out 3 quarts from A to C. A=4, B=1 and C=3.
(8) Transfer C to B. A=4, B=4 and C=0.

Done! Shorter maybe.....

- Manish
[ March 24, 2006: Message edited by: Manish Hatwalne ]
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Dear Hat Waale/ Joshi.


Yes Thats right. Now this question should be closed. Rakesh do you have any query regarding this question. Please ask to Hat Waale. otherwise give your confirmation.



The Best way to predict your future is to create it - Every great individual common man
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

Originally posted by Ankur Sharma:
Dear Hat Waale/ Joshi.


Yes Thats right. Now this question should be closed. Rakesh do you have any query regarding this question. Please ask to Hat Waale. otherwise give your confirmation.



Ankur,

I have a proper name - Manish. Please use that and do not make fun of my surname, though you may not have inteded it that way.

- Manish
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
0- A8 B0 C0
1- A3>B5 C0
2- A3 B2>C3
3- A6<B2-C0
4- A6 B0>C2
5- A1>B5 C2
6- A1 B4>C3
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
See Die Hard with a Vengeance..the answer is in there. This is an AI question.
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Ankur,

I have a proper name - Manish. Please use that and do not make fun of my surname, though you may not have inteded it that way.

- Manish
---


Manish I am really sorry for that, if you hurt but beleive me that was not intended that was totally a typo mistake........ pls don't get hurt... I extremly apolozise for this typo mistake.........

I hope now onwards you don't have any wrong spirit for me...


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing the peanut oil