Wednesday, December 19, 2012

camel water, gas to market, elephant banana problem

This problem is probably of folk lore and has gone under several names and settings, basic structure is this:

You have 3000 bananas and need to transport from A to B, the distance is 1000 units and you have 1 elephant. The elephant has a capacity of 1000 bananas and to move 1 unit, the elephant will consume 1 banana. The question is, what is the maximum banana you can transport from A to B, using that elephant? Notice that the elephant may deposit bananas along the way from A to B at any point, not necessarily integral points, for example, it could deposit 3 bananas at a distance of 100/3 units from point A.

Many of us know the solution, but I haven't seen a proof yet.

First the solution:
while the remaining bananas are more than the capacity, you calculate the next point that the elephant can have a reduced number of trips. In the given instance, you need at least 5 one-way trips to move all bananas by 1 unit of distance. The number of trips will reduce when the remaining bananas drops to 2000, then the elephant needs 3 one-way trips, and when the bananas drop to 1000, the elephant can just carry all of them and move to B.

It is in fact an optimal strategy, but why?

Our goal is to show that any proposed optimal strategy cannot beat our strategy, but there are so many ways to move and a strategy can be an arbitrary combination of any of those moves, as long as you have enough bananas.

First observation: Any optimal strategy has to use all 3000 bananas. This is almost obvious since we can always pad a strategy by inserting some preliminary moves to waste all bananas it left at point A.

Now we need a second assumption. Let p be a point between A and B. We fix a proposed optimal strategy S. We say that an event occurred at point p in strategy S if an elephant ever dropped some bananas at point p or ever turned around at point p. We use p0 to denote the smallest p with an event. Now we assume p0 is at finite distance from A. (I am not sure how to justify this but it seems natural for moving an infinitesimally small distance from A does not make much sense).

OK, since our nearest event occur at p0, we can interpret strategy S as moving all bananas to p0, with a reduced number of bananas, and then follow the other moves. This does not change the ultimate gain of strategy S. Suppose the distance from p0 to B is L1, and the number of bananas remain is B1, it is possible to show that our strategy will leave at least B1 bananas at p0. Since having more bananas cannot hurt, we can recursively reduce the instance from (L, B) to (L1, B1), then to (L2, B2), up to the point that the remain Bk is no more than 1000, and then it is obvious that our strategy is optimal as the elephant should take all bananas and make one move to B. This will be our base case. The (L, B) pairs are strictly decreasing by a finite amount every time, because our assumption, then we have an inductive flavor proof by reducing the instance!

It feels right to me, although a lot more work needs to be done to formalize it and justify all details.

No comments:

Post a Comment