elephant with 3000 bananas

6 views
Skip to first unread message

bhargava

unread,
Jul 6, 2011, 7:02:28 AM7/6/11
to freak...@googlegroups.com
You have a elephant and 3000 bananas with you, you have to use the elephant to carry the bananas.

You have to travel a distance 1000 KM, the elephants eats 1 banana for every KM it walks.
The elephant can carry only upto 1000 bananas

How many bananas can you manage

Rajesh Inakota

unread,
Jul 6, 2011, 7:03:59 AM7/6/11
to freak...@googlegroups.com
I know answer to this :)
--
Regards,
Rajesh.I

SURI

unread,
Jul 7, 2011, 4:23:31 AM7/7/11
to Freak-Your-Mind [FYM]
We need to do this in multiple hops. We need to remember that elephant
requires bananas even in return journey.

Also, some one drop generalized formula to calculate this when
distance is D km, number of bananas are N, can carry only D number of
bananas and requires one banana per km.

--SURI

On Jul 6, 4:03 pm, Rajesh Inakota <rajesh.inak...@gmail.com> wrote:
> I know answer to this :)
>

bhargava kumar

unread,
Jul 7, 2011, 5:26:55 AM7/7/11
to freak...@googlegroups.com
I couldn't arrive at a formula, but below is a program to calculate it

assuming N is divisble by D

bananas_left = N
distance_left = D
while (distance_left > 0 ) {
         trips = bananas_left/D
         distance = D / (trips * 2 - 1)
 
         if (distance < distance_left)
                bananas_left = bananas_left - D
         else {
                bananas_left = bananas_left - ( (trips * 2 - 1) * distance)
                distance_left = 0

Devendra Bhatte

unread,
Mar 3, 2016, 5:31:32 AM3/3/16
to freak...@googlegroups.com
Hello everybody,
Is the answer 250?
Regards,
Devendra
--
Thanks & Regards,
Devendra Bhatte
Reply all
Reply to author
Forward
0 new messages