A gorilla harvests 3,000 bananas and needs to carry them 1,000 miles to
the supermarket. He can only carry 1,000 at a time. Since he is a
gorilla he eats 1 banana every mile he goes in any direction. He can
(and will have to) leave bananas anywhere along the way. Once all his
bananas have reached the end he DOES NOT need any to eat to get back.
Remember he eats 1 banana every mile he goes even if he is going back to
pick up more bananas. What is the maximum number of bananas he can get to
the market ?
(Other versions of this problem use a camel named Corey, or have other
variations.)
When he has more than 2000 bananas, it costs him 5 bananas / mile to
transport them, since he makes 3 trips forward and 2 trips back.
When he has more than 1000 bananas, it costs him 3 bananas / mile, for 2
trips forward and 1 trip back.
And when he has 1000 or fewer, it's 1 banana / mile.
I think the way to do it is: see how far he can get 2000 bananas, then 1000
bananas, and then make one final trip.
200 miles @ 5 bananas / mile = 1000 bananas cost.
So if the first stopping point is at 200 miles,
he would carry 1000, eat 200, drop 600, and eat 200.
Then he would do that again.
On the third trip, he doesn't eat the second 200, so at the 200 mile
marker he has 600 + 600 + 800 = 2000 bananas.
If the second leg is 333 miles, it works out as:
carry 1000, eat 333, drop 334, eat 333.
carry 1000, eat 333, drop 667.
Now he has 1001 bananas, and it's just as well to throw one away. To
make it come out exact, we'd need to use fractional miles and fractional
bananas.
Now we have 1000 bananas at the 533 mile marker.
For the last leg, he just carries the last 1000 bananas,
eating 467 along the way, and arriving with 533 bananas.
If the initial legs are shorter, it works out the same.
If the initial legs are longer, he does more miles at higher banana /
mile rates, ending up with fewer bananas.