Fog Creek Software
Discussion Board

Hungry Elephant

this one is a easy puzzle

there are 2 cities A and B, dist. between them is 1000 Km
we have 3000 bananas in city A and a elephant
can carry max 1000 bananas at  any given time and it needs to eat a banana every 1 Km

How Many Max. No. of bananas u can tranfer to city B???

note : the elephant cannot go without bananas to at.

Wednesday, April 7, 2004


Go 250km drop off 500, go back.
Go 250km drop off 500, go back.
Go 250km, now you have 1750 at 250km.

Go another 250km to 500km, drop off 500, go back.
Pick up remaining 750, go to 500km.

Now you have 1000 bananas at the 500km mark.

The trip to the end leaves you with 500 bananas.


Wednesday, April 7, 2004


Pick up 1000, go 200 km, drop 600, return. Pick up 1000, go 200 km, drop 600, return. Pick up 1000, go 200 km, drop 800. Now you have 2000 bananas at 200 km.

Pick up 1000, go 333 km, drop 334, return. Pick up 1000, go 333 km, drop 667. Now you have 1001 bananas at 533 km.

Pick up 1000, go 467 km, drop 533 banans. You now have 533 bananas in city B and one banana rotting away at 533 km.

Thursday, April 8, 2004

very good thats the correct Answer 533

Saturday, April 10, 2004

I'll sketch my thought process.

First, I realized that if you take 1000 bananas and walk 1000 kilometres, you arrive with no banana at all (and the elephant is stuck in city B). So the elephant has to travel shorter distances (but more often).

So, I asked myself, why not carry the bananas kilometre by kilometre. It needs to walk five times one kilometre to move the bananas one kilometre forward (which costs five bananas). At 200 km, you have only 2000 bananas left, so you only need to walk three times to get the bananas one km farther. I arrived with 533 bananas in B (an optimal solution), but the poor elephant! It must feel dizzy of turning around so often.

That's not what I thought at that moment. I was happy that I had found a solution (which I believed to be correct (which it was)) and went to bed.

The next day, I realized that it's not necessary to make the elephant turn around so often. Transporting the bananas two kilometres is the same as transporting them one kilometre twice (as long as you don't cross the 2000 banana line or the 1000 banana line). I have posted the simplified solution above.

The logical explanation for the solution is this one: As long as you have to walk every kilometre five times, each kilometre costs you 5 bananas, so you want to stop that as soon as possible. Which is when you have only 2000 bananas left, which is after 1000 km / 5 = 200 km. Daws' elephant walks the first 250 km five times, wasting some bananas here. (Daws, I hope you aren't offended. I just try to explain why your solution is suboptimal.)

So with only 2000 bananas left, every kilometre costs 3 bananas, which we want to do until you have only 1000 bananas left, and no farther, because with only one way to walk, transportation becomes even cheaper. Now 1000/3 is not an integer, so we lose one banana due to rounding.

That last part sound really odd. People in B will ask: "Why have you left one banana on the road?" - "I couldn't do anything about it; rounding error." - "WHAT?"

Sunday, April 11, 2004

Sorry i feel the answer is 534

B : Bananas
now when we reach 533KM we have 1001 B

so pick 1000 B and go 1/3 KM
drop 1000 B and come back 1/3 KM
and pick 1 B and go 1/3 KM

so now we have 1000 B at 533 + 1/3 KM
and we dont have to give a B for travelling 2/3 KM at the end

so we reach with 534 B

cool :-)

Wednesday, April 14, 2004

The puzzle said that the elephant cannot go without bananas to eat.

However, that statement is ambiguous.  It needs to specify whether the elephant eats the banana before going 1km, or eats after going 1km, or eats somewhere along the 1km.  Does it eat the whole banana in one gulp, or takes little bites.

If one is to find a precise and clear-cut solution, the statements in the problem must be precise.  Unless you intend to play tricks on words.

Wednesday, April 14, 2004

Answer is 833 Bananas

1. Go 1 Km and leave 999 repeat this for another 2 times.
2. Now u were left with 2997 bananas
3. Repeat this process untill u will be left with less than 2000 bananas. ()

4. Now go 1 KM in two sets (1000 + 1000) as u were left with below 2000 bananas
5. Repeat this process untill u will be left with less than 1000 bananas. ()

6. Now keep going the city B at the end you will be left with 833 banas

  b NUMBER := 3000;

  dbms_output.put_line(' b : '|| b);
  FOR i IN 1..1000 LOOP
    IF b > 2000 THEN
      b := b - 3;
    ELSIF b > 1000 THEN
      b := b - 2;
      b := b - 1;
    END IF;
  END loop;
  dbms_output.put_line(' b : '|| b);

Tuesday, July 20, 2004

*  Recent Topics

*  Fog Creek Home