An Algorithmic Camel

Logic Level 3

You have to cross a large desert covering a total distance of 1,000 km between Point A and Point B. You have a camel and 3,000 bananas. The camel can carry a maximum of 1,000 bananas at any time.

The camel eats the bananas at a constant rate of one banana per kilometer travelled. What is the maximum number of uneaten bananas (rounded off to the closest whole number) that the camel can transport to the other end of the desert?


On the face of it, it seems that you can’t transport even a single banana uneaten to the other end of the desert. However, if that would have been the case, I wouldn’t have posted it and wasted your time.

Hint: You have to make multiple trips back and forth as you transfer all 3000 bananas. Find the most efficient way.


The answer is 533.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

13 solutions

Satyen Nabar
Feb 23, 2014

At KM # 0, we have 3000 bananas. The maximum bananas the camel can carry is 1000 so the camel must make at least 3 trips from the start point. (Leave #0, Return to #0, Leave #0, Return to #0, Leave #0). If we move just 1km, we need 1 banana for each step mentioned above thus making a total of 5 bananas for each km.

We continue making 3 trips until we reach a banana count of 2000.

3000 – 5*d = 2000 => d = 200

At 200km, we will have 2000 bananas

At this point, we only need to make 2 trips (Leave #200, Return to #200, Leave #200). This will cost 1 banana for each step thus making a total of 3 bananas for each km.

We continue making 2 trips until we reach a banana count of 1000.

2000 – 3*d = 1000 => d = 333.333 km

At (200+333.333) = 533.333 km, we will have 1000 bananas.

At this point, we need to make one trip so the camel just carries everything and marches toward the market.

Remaining km = 1000 – 533.333 = 466.666 km. Bananas needed = 466.666

Therefore, the bananas remaining once the camel reaches the market is 1000– 466.666 = 533.333 bananas

Rounded off to 533 bananas.

I think the question should make it clear that the camel needs to eat bananas in order to travel. Even though it makes sense that a camel needs food to walk, I incorrectly assumed that if you were carrying no bananas, the camel wouldn't eat any but would still be able to travel.

D C - 4 years, 10 months ago

Log in to reply

Agree. A bit ambiguous whether they need to eat one for every km or just eat one per km whenever they have access to one.

Sindri Saevarsson - 4 years, 7 months ago

Can you justify why "We continue making 3 trips until we reach a banana count of 2000" is the optimal solution? Why not till we reach 2200? 2500?

It's a good question otherwise.

Calvin Lin Staff - 7 years, 3 months ago

Log in to reply

Dear Calvin,

Starting with the 3000 bananas with 1000 miles to go, let the camel take bananas to a point m miles away from the start.

To get there, it will eat m bananas, but it has to come back to get the next lot, so the camel needs m more bananas to do that. Same for the next batch of bananas.

But for the third batch it doesn’t return to the base (as there are no bananas there any more). That’s three trips out, and two trips back, giving five trips altogether, so the camel will have eaten 5m bananas.

Altogether that means it will have taken 3000-5m bananas.

Now the best strategy requires the camel should end up with 2000 bananas at a distance m from the base, so m = (3000-2000)/5 = 200 miles.

1st trip load 1000, eat 200, drop 600, bring back 200 for the road, 2nd trip the same. 3rd trip load 1000, eat 200, drop 800.

I must admit that i solved it by trying various combinations till i was sure that 533 and 1/3 was the absolute maximum that could be transported.

However a more detailed math explanation can be obtained at this link http://math.stackexchange.com/a/96012

Satyen Nabar - 7 years, 3 months ago

Log in to reply

Thanks. As you can see (even in the link), you need to justify why those distances are the optimal, other than just saying that "I tried various combinations", or "go till 2000 bananas" which is arbitrary.

What is the relevant insight that the optimal occurs at those points? What are you trying to maximize / minimize, which leads to those points being the best 'stopping place'?

Calvin Lin Staff - 7 years, 3 months ago

Log in to reply

@Calvin Lin Dear Calvin,

After 200 kilometers, something important happens. At this point, the camel will have eaten 200 x 5 = 1,000 bananas, leaving just 2,000 remaining.

Because the camel can carry 1,000 bananas at a time, the camel will only need to double back once.

Before that With 3,000 bananas, the camel will need to double back two times. To carry the initial heap by 1 kilometer, the camel will need to make 5 trips and eat 5 bananas. This process can be repeated and the camel will slowly transport and eat the bananas.

Because the camel can carry 1,000 bananas at a time, the camel will only need to double back once. To carry the remaining heap by 1 kilometer, the camel will only need to eat 3 bananas.

The second leg therefore requires just 3 bananas per kilometer.

How long will this be necessary? After 333 1/3 kilometers, the camel has devoured another 1,000 bananas.

At this point, there are just 1,000 bananas left: the camel can make the remaining journey without doubling back. This means the camel can carry all the remaining 1,000 bananas and complete the trip.

Satyen Nabar - 7 years, 3 months ago

Hehe, I thought this when I solved it the first time. What should be the optimal value.

I backtracked. If I have 1000 at any point, I can carry all of them straight up, without any pit-stops.

So, I have to find a point where I have carried 1000 bananas, and that point has to be as close to the destination.

So, I tried two things:

Either reduce 3000 directly to 1000 ... or take a middle pit-stop at 2000 bananas.

In the two scenarios, I found, the 1000 bananas is reached closer to the destination in the 2nd scenario.

If I think about it, Maximizing the number of Pit stops, carrying the maximum number of bananas at each stage, MUST minimize the 1000 banana stage from the destination.

Soumya Chakraborty - 7 years, 3 months ago

It's impossible for the camel to carry more than 2000 bananas using fewer than 3 trips, so if we stop making 3 trips at an earlier count, that means we must be throwing bananas away along the way. (e.g. say we stopped making three trips at 2500, we'd leave 500 bananas stranded in the desert because we could only continue carrying 2000 at that point).

Because each pile of bananas that contains at least two bananas effectively "pays for" itself, any solution that introduces extra steps to avoid throwing away more than one banana can be no worse than a solution that does not. So even if an optimal solution exists that throws away some amount of bananas > 1, we could easily transform it into one that does not. We can therefore freely make the assumption that the optimal solution we're finding does not throw away more than 2 bananas.

Niklas Haas - 1 year, 2 months ago

Another simpler way to look at it is from the greedy approach. So with each banana the camel eats we want to carry the maximum number of bananas to a maximum distance while also returning back to carry more. This means that for each banana the camel eats, we can move a distance of 0.5km, dump the load and get back for more. All we need to ensure is that every time we carry the maximum number of bananas possible. So if the number of bananas is more than 1000, we carry 1000, otherwise we carry as many as there are. A simple matlab code for solving this problem is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function thisend=camel()

bananas=3000;

gap=0.5  %the distance we move forward with the load before returning back

otherend=0;  %the number of bananas at the end of gap

thisend=3000;  %the number of bananas at starting point

for i=1:gap:1000

    otherend=0;

    if(thisend>1000)

        while(thisend>1000) %for each round trip

            otherend=otherend+1000-(2*gap); %accounting for the bananas on the other side of gap

            thisend=thisend-1000; %accounting for the bananas on this side of gap

        end

        otherend=otherend+thisend-(1*gap); %no round trip the last time

        thisend=otherend;

    else

        thisend=thisend-(1*gap);

    end

end 


it return 533.5 which is rounded to 533.

Tanmay Gupta - 7 years, 3 months ago

Log in to reply

It doesn't specify if the camel eats 1 banana traveling 1km in any direction, the solution seems that it eats 1 banana per 1km heading in the direction from A to B. Not considering the distance back to point A to restock your banana's. That's what had me stumped, I believe it would be zero if it ate 1 per km no matter what direction it travels

Corwin Farmer - 3 years, 3 months ago

Wait... lets say the camel starts by carrying 1000 bananas, moves to point X, drops the remaining (1000-X) bananas, and returns to the starting point empty, how can it eat anything on the way back???

Fareed Al-Bender - 5 years ago

Oh, I didn't realize that the camel needed to eat on the way back. Without that rule I believe that it would be 833. (334+499)

Alex Li - 5 years ago

@Satyen Nabar Not an original problem. Remember solving this almost 20 years back on Ask Dr. Math: http://mathforum.org/dr.math/faq/faq.camel.html Rather than reproducing this verbatim, the numbers could have been modified to get a nice integer answer. There is a nice 'graphical' method of solving this. I had posted it to Mensa Mumbai Puzzle SIG

Ujjwal Rane - 4 years, 9 months ago

Since I can not find a way to post on my phone - I am using reply to post my train of thoughts on the solution.

I figured since the camel can only carry 1000 bananas you would need 2 stops to go from 3000 to 2000 to 1000 and then walk the last distance with the remaining bananas. To get from A to stop1 would take at least 5 trips to and fro so to reach stop1 with 2000 bananas the camel gets to eat a max of 1000 ÷ 5 = 200 bananas on the distance A to stop1 which equals a max distance of 200km. To transport the remaining 2000, you'd need 3 trips to carry all bananas. So the max distance between stop1 and stop2 on eating 1000 bananas would be a third of 1000 = 333 1/3 km. Hence at stop2 (200+333 1/3 = 533 1/3 km from A) you have only trip left to carry the remaining 1000 bananas to B. As the camel will eat again a banana for every remaining km (which are 466 2/3 km), upon arrival in B you will be left with 533 1/3 uneaten bananas, i.e. 533 really uneaten ones.

Karen Mulders - 3 years, 4 months ago

Ok I forgot you have to travel back too so I got over 800 bananas. But all the solutions down here make my head spin. SO: You want to have 2000 bananas (exactly 2 times the camel can carry) left the first drop point. You have to make 5 trips (3 to go 2 back) . 1000/5=200 bananas equals 200 km to first drop point. Then on the second drop point you want to have 1000 bananas left. You have to make 3 trips (2 to go 1 back) makes 1000/3= 333,3333333 km further. Now you traveled 200+333,3333333= 533,33 km so you have 1000-533,33=466,66 km left to go with 1000 bananas. The camel eats 467 bananas (yes he ate 0,333 piece left too) so you have 533 bananas left.

Koos sam - 2 years, 10 months ago

I used a dynamic programming algorithm to solve this :D

With an array A, Let A[i] stores the maximum number of bananas that we can carry from the km #0 to km #i. At initial, A[i] = 3000 - i * 5 (i = 0 ..1000).

Next, with each km #i (i = 2..1000), we consider the road from km #1 to km #i - 1. If there is a km #j (j = 1..i - 1) from which we can carry more bananas to km #i, then we choose km #j to be the preceding point of km #i (means that we have to go to km #j, and then from km #j to km #i, in order to carry the maximum number of bananas to km #i)

As a result, A[1000] will be the maximum number of bananas that we need to find. With another array to save the preceding points, we can trace back and get the traveled kms.

The solution using this algorithm is

0 -> 1 -> 200 -> 534 -> 1000 with the maximum number of bananas is 532

0 -> 1 -> 200 -> 534 -> 999 with the maximum number of bananas is 533


bananas = 3000;
rate = 1000;
distance = 1000;

A = array();
trace == array();

for (i = 0; i <= distance; i++)
{
    A[i] = bananas - (i * 5);
    trace[i] = 0;
}


for(i = 2; i <= distance; i++)
{
    max = -1;
    for (j = 1; j < i; j++)
    {
    // Next 4 lines: calculate and get the best choice      
        temp = (A[j] - (i - j) * (ceil(A[j] / rate) - 0.5)*2);

    // We can actually dump some bananas if it costs more than we can carry        
        rem = A[j] % rate;
        if ((rem > 0) && (rem < (i - j)))
            temp -= rem;

        if (max < temp)
        {
            max = temp;
            A[i] = temp;
            trace[i] = j;
        }
    }
}

I wrote a solution, had some mistakes, deleted it and could not write another one, so I post it as a comment here :D

Cường Nguyễn Tấn - 7 years, 3 months ago

I think 534 is the answer and that is optimal solution. At point (200+333) km we will have 2000-999 = 1001 bananas. Then we will have 1000 bananas in 534 km, since camel eat 1 banana before start. And then no back travel and we will have 999 in 535 km, 998 in 536 km, 997 in 537 km ...... 534 in 1000 km. So correct your answer please.

Zakir Dakua - 5 years, 6 months ago
Anurag Poddar
Mar 9, 2014

Best way: Carry 1000 of them from 0 to 1. Keep 998 there and return to 0.(Net -2 bananas) Do this once more. (-2). Now carry the 1000 remaining from 0 to 1 (-1). Hence we have transported 2995 bananas from 0 to 1.

Note that whenever ceil(no.of banana/max capacity) = n, we will end up losing 2*n-1 banana when transporting by 1 km fwd.

Hence, we will reach 200 with 2000 bananas remaining. Hence, we will reach 200+333 with 1001 bananas remaining. Now just carry all the 1000 bananas from 533 to 1000, thus transporting 533 bananas

The way you mentioned the problem, it seemed to me that, the camel needs 1 banana after it walks 1 km. So when 466.66 km were remaining it would have eaten only 466 bananas when it reached the destination according to this understanding.

I agree you mentioned "closest whole number" and i ignored it and posted the answer as 534.

However, it's also hard to imagine a camel eating 0.3 banana per 300 meters, 0.2 banana per 200 meter etc and that too in a continuous fashion :).

Anyway the solution was thought like:

  1. In the beginning, walk 1/5 k.m. back and forth so as in 5 trips, all the bananas are transported to next 1/5 k.m. That means 5 bananas per km

  2. after 200 k.m. 1000 bananas are finished, so now start moving 3 trips back and forth per km each of 1/3 km. which means 1000 bananas will we finished in next 333 + 1/3 = 333.33 k.m.

  3. Now we are left with 1000 bananas with 1000 - ( 200 + 333.33 ) = 466.67 k.m. to walk. So before it completes the 467th k.m. it has already reached the destination. So the bananas eaten upto there = 1000 + 1000 + 466 = 2466. So uneaten bananas: 3000 - 2466 = 534

Rampal Chaudhary - 7 years, 3 months ago

You have little mistake, answer will be 534. Since 1001 bananas in 533 km, 1000 will be in 534 km, so on 999 in 535 km,,,,,,, 534 bananas in 1000 km.

Zakir Dakua - 5 years, 6 months ago
Luciano Riosa
Dec 16, 2014

The point in this problem is that we have to maximize every load the camel is carrying. Till the camel can carry a maximum of 1000 bananas, at each stopping spot we have to get a number of bananas that is a multiple of 1000. In our case 2000 and 1000. To get 2000 at the first stop we have to consume 1000 bananas, and since five trips are needed, we fix the stop at 200 km. Next, for having 1000 bananas at the second stop, again we need to spend another 1000 bananas, this time in three trips. So we reach the point 200+1000/3=533+1/3, from which with a single leap we reach the finish line, delivering 1000-(1000-533-1/3)= 533+1/3 bananas. This is a general solution which can be applied to any set of the three initial data. Surprisingly and mathematically speaking, there is another solution which gives however the same result: a number of infinite trips of infinitesimal length...

The answer is 0 travel 1000 km eating 1 per km so get back requires another 1000 so the camel dies on a return trip because it is out of food

Rob Jones - 2 years, 4 months ago
Hữu Nguyễn
Apr 5, 2014

follow the strategy: carrying 1000 bananas, move 1km, drop bananas, go back 1km, carrying other 1000 bananas until no bananas left. we have the map of bananas as follow.

km 0: 2999

km 1: 2994

km 2: 2989

1 km cost 5 banana => 200km cost 1000 banana

km 200: 1999

km 201: 1996

km 202: 1993

1km cost 3 banana => 333km cost 999banana

km 533: 1000

1km cost 1 banana => 467km cost 467banana

km 1000: 533

Ambareesha Aithal
Mar 25, 2014

I solved it using simple excel sheet.

Column A: KM/step

Column B: Number of Bananas carried on first trip to this KM/step

Column C: Number of Bananas left at previous step after first step

Column D: Number of Bananas carried on second trip to this KM/step

Column E: Number of Bananas left at previous step after second step

Column F: Number of Bananas carried on third trip to this KM/step

Column G: Total number of Bananas remained uneaten

It should look something like this:

0 0 0 0 0 0 3000

1 999 1999 999 998 997 2995

2 999 1994 999 993 992 2990

3 999 1989 999 988 987 2985

....

With this approach you can visualize how each step is executed. Interestingly. I can save 534 bananas! Here is how: At step 533 I will be left with 1002 bananas. At 534, camel eats one banana and brings 1000 bananas to 534 milestone. I don't need to go back to milestone 533 which is left with 1 banana. This will save me 1 banana to go back. So I will be left with one additional banana! 534!

First of all, it never hurts to make general observations before diving in straight into whatever the first way of solving the problem comes to you and doing all kinds of computations. The first thing to note here is 1 km travelled = 1 consumed banana whatever the natural obstacles are (those don't concern us), so the consumption is constant across any travelled distance . Secondly , it makes intuitive sense that the camel should somehow consume the least amount of bananas as possible while carrying most of them as possible . So, to achieve that, since it's 1 banana/1km, the camel should travel to the shortest distance possible (1 km) with maximum amount of bananas as possible, thereafter leaving the bananas at the end of the travelled distance. So continuing with the thoughts of the "second observation", we make the following route: 1) travel one kilometer with 1000 bananas, leave 998 bananas, consume 2 bananas in total on the way forward and on the way back; 2) repeat the same process (which cost us 4 bananas, taking into account the 1-st step); 3) now all we have to do is to just travel 1 km with 1000 bananas (having consumed 5 bananas in total). Thus, we have travelled 1 km (with 5 trips to and fro) and carried over 2995 bananas with 5 bananas consumed along the way. So we continue doing that till we consumed 1000 bananas and travelled 200 km (it is because we have bananas > 2000, which necessarily means we have to make 5 trips). The procedure that follows will be quite similar, but now we need to carry over only 2000 bananas over 1 km, which requires only 3 trips to do this (which costs us 3 bananas). We continue doing that till we are left with 1000 bananas (again the line of reasoning is very similar: we have bananas > 1000, which necessarily means we have to make 3 trips to complete 1 km). Thus, we travelled 333.33... km. Now we 200 km + 333.33... km = 533.33... km, which means we have 466.66 km left to travel, which costs 466.66 bananas, in the end leaving us with 533 bananas (because we were left with 1000 bananas). To express this idea a little bit more differently: Let m be the maximum amount of bananas the camel can carry at a time (which is 1000 bananas); we have 3m in total. So we carry over m to the shortest distance travelled, return, carry over m to the shortest distance again, return, carry over m to the shortest distance, thus traveling 5 km in total (consuming 5 bananas). We continue doing this till we consumed m bananas, leaving us with 2 m. So we carry over m to the shortest distance, return, carry over m to the shortest distance once again, thus traveling 3 km in total (consuming 3 bananas). We continue doing this till we consumed m, leaving us with m. Let us travel s distance till we consumed 2 m bananas, till we left with m bananas: s = m/5 + m/3 Also after being left with m bananas we have to travel 1000 km - s distance more. So bananas remaining after the "journey" are m - (1000 - s). So we just find s, because we know what m is (1000): s = 1000/5 + 1000/3 = 533.33... and bananas remaining after the "journey" are 1000 - (1000 - 533.33) = 533.33...

Suneet Bendre
Apr 23, 2014

I used Dynamic Prg, Below is the matrix and logic:

e.g: Distance=4, TotalFruit=10, MaxCanCarry=6

                             Hops/ Distance: -->      1    2    3    4


          Ferry( One side KM journey i.e 1KM) :       0    7    4    3


                                         2KM  :       0    0    4    3

int pointA2B = (maxCarry/2)-1; // Max distance can be taken [(1000/2)-1) = 499]

    for(int hops=0; hops<pointA2B; hops++)
    { 
        int score = totalFruit;
        int lastFerry;
        scoreMatrix[hops][0]=0;
        for(int distIterate=(hops+1); distIterate<dist; distIterate++)
        {
            lastFerry = (score%maxCarry);        // Remainder of last round for respective KM 
            if(lastFerry!=0)                        
            {
                score = ((score/maxCarry)*(maxCarry-((hops+1)*2)));  
                                                                       // (n-1) rounds * Max-To&FroDistace camel will consume 
                score += (lastFerry-(hops+1));     // Last round so Remaining fruits-distance
            }
            else
            {
                score = (((score/maxCarry)-1)*(maxCarry-((hops+1)*2)));
                score += (maxCarry-(hops+1));
            }
            scoreMatrix[hops][distIterate]=score;
            distIterate+=hops;
        }
    }
}
Adrian Iriciuc
Mar 13, 2014

You need to make small trips back and forth. Since there are 3000 bananas first we will need 3 trips. After we consume 1000 bananas we will only need 2 trips to move all the bananas so we will move more optimal. Again, after we consume another 1000 bananas we don't have to come back since we can carry all the remaining bananas.

We need to calculate the length of the trips carefully so we end up with 2000 bananas in one place and not less. For example a bad way would be to make 300km in a trip. This way first trip saves 400 bananas, second trip 400 bananas and last trip saves 700 bananas. In the end we would have 1500 bananas and that's bad because we want to make only 2 trips once we get 2000 bananas or less.

Optimum is to make trips of 1km, or 2km, or anything that divides 200(because you need 5 bananas for each km, and you want to consume 1000 bananas). So if you make trips of 200km then first trip you save 600, second trip you save 600 and last trip another 800 bananas, leaving you at one place with 2000 bananas.

Now you start making series of 2 trips in such a way you remain with only 1000 bananas in one place. Same logic as above, but you need only 3 bananas for each km so you can walk another 333 km until you end up with 1000 bananas in one place.

Total so far you walked 533km and you have 1000 bananas left. From this point you just walk forward and end up with 533 bananas.

Guru Babu
Mar 7, 2014

1st 200km with 1000 bananas(5 bananas for each km), 333 km with 999 bananas( 3 bananas for each km) and remaining 1001 we should cover 467 kms .for 1km require 2 bananas, then remaining 999 bananas-466kms=533

nice, me too.

Scofield Itdev - 7 years, 3 months ago
Prathap Ns
Mar 6, 2014

first, the camel takes 1000 bananas to point A. There it drops 600 bananas and returns with 200 bananas. Then the camel takes again 1000 bananas to point A. Again, it drops 600 bananas and returns with 200 bananas. After this, the camel takes the last 1000 bananas from the plantation to point A. From point A, it leaves with 1000 bananas to point B. In point B, it drops 333 1/3 bananas and returns with 333 1/3 bananas. Then it takes the second load of 1000 bananas from point A to point B. Finally, it carries the 1000 bananas from point B to the market, where it arrives with 533 1/3 bananas.

If we have more than 2000 bananas every mile of transportation cost us 5 banans. From 1000 up to 2000 - 3 bananas. So it give us 200 miles for first 1000 bananas, than 333.3(3) miles for next 1000 banans. And we have to go next 466.6(6) miles for 1 banana per mile - the final result is 533.3(3) banana. Round to 533.

Maxim Fedorov - 7 years, 2 months ago
Dagh Nielsen
Dec 6, 2016

Here's a proof that 533 bananas is optimal.

We move right from A to B, with 1000 km between A and B. The key idea is to look at the total number of different bananas that reach various points between A and B from the left (without being taken back left).

1) Notice first that in any strategy, the total number of different bananas reaching a point between A and B from the left is strictly decreasing with the distance from A. If y is to the right of x, all bananas at y must have reached x too, and in order to arrive at y, the camel must have eaten some of the bananas that reached x, and hence there are less bananas reaching y.

2) From this follows that in any given strategy, there is a unique point where exactly 3000 different bananas arrived (of course this is the start), and another unique point where exactly 2000 different bananas arrived from the left. We call them x 3 x_3 and x 2 x_2 . (Similarly, the point where exactly 1000 different bananas arrived is called x 1 x_1 and so on for x n x_n .)

3) We make an upper bound for the distance between x 3 x_3 and x 2 x_2 . Looking at any point between x 3 x_3 and x 2 x_2 , we know from 1) that the camel brings strictly between 2000 and 3000 bananas to that point from the left. This means that the camel must arrive at the point from the left at least 3 times (since the camel can only carry at most 1000 bananas). For every time the camel arrives except the last, the camel must go back left in order to arrive again. This means that the camel traverses at least 3 + 2 = 5 3+2=5 "paths" to the immediate left of the point. Since this is true for all points between x 3 x_3 and x 2 x_2 , the camel eats at least 5 bananas pr. kilometer between x 3 x_3 and x 2 x_2 . The camel eats exactly 1000 bananas between x 3 x_3 and x 2 x_2 , and thus the maximal distance between x 3 x_3 and x 2 x_2 is 1000 / 5 = 200 1000/5=200 in any strategy.

4) Similarly, the maximal distance between point x 2 x_2 and point x 1 x_1 in any strategy is 1000 / 3 1000/3 . Generally, the maximal distance between point x n x_{n} and x n 1 x_{n-1} is 1000 2 n 1 \frac{1000}{2n-1} .

5) When we reach x 1 x_1 in any strategy, the maximal number of bananas we can bring to B is the distance travelled so far. The maximal distance between x 3 x_3 and x 1 x_1 is the sum of the maximal distances between x 3 x_3 and x 2 x_2 , and x 2 x_2 and x 1 x_1 . This is 1000 / 5 + 1000 / 3 = 200 + 333 = 533 1000/5 + 1000/3=200+333=533 .

6) Generally, if we start with n n kilo bananas, we can travel at most

1 + 1 / 3 + 1 / 5 + 1 / 7 + . . . + 1 / ( 2 n 1 ) 1+1/3+1/5+1/7+...+1/(2n-1)

thousand kilometers.

7) We notice that the upper bound we have established can indeed be reached by travelling 2 n 1 2n-1 number of times between x n x_{n} and x n 1 x_{n-1} with full loads from the left.

Charlz Charlizard
Jun 25, 2015

Let 3x+y=1000 for the first trip.x=max distance reach by the camel in 1st trip. 2x bananas for forth and back journey.And 1 banana is kept at each kilometer(optimal strategy-so that in the last trip, he will have exactly 1000 bananas upto certain distance(x+z)), so required bananas are x.Total=3x.. y bananas are kept at xth kilometer(for second trip purpose)

Let 3z=1000-2x+y for second trip.z=max distance reach by the camel in 2nd trip prior to x. 3z bananas using the same method as used for the 1st trip.Here from 1000-x-(x-y) -x because the bananas at each kilometer are for the 3rd trip, so not to consume in the 2nd trip, and -(x-y) for the return trip bananas considering the y bananas that are already placed at xth kilometer.

2nd trip equation becomes 3z=2000-5x(by equating 1st and 2nd trip equation) so z=(2000-5x)/3

Now for 3rd trip. The bananas that can be transported to other side are x+z(by consuming the bananas left at each kilometer) x+z=x+(2000-5x)/3=(2000-2x)/3=f(x)

Now here as the camel has limitation , it can only carry 1000 bananas so 200<=x<=400(for this strategy)

Now from the equation f(x)=(2000-2x)/3..f(x) is max. when x is min. i.e x=200. so f(x)=1600/3=533.33333...which means 533 whole bananas are transported leaving .33333.. of the bananas

Nam Diện Lĩnh
May 10, 2014

Using javascript to simulate the moves the camel like this code below (can run directly in your browser console):

var camel={
    setUp: function()
    {
        this.pos=0;
        this.length=1000;
        this.maxNum=1000;
        this.remain=3000;       
    },
    move: function(step)
    {
        if(this.remain<=step||this.pos>=this.length)
            return false;

        this.pos++;
        var r=step;

        while(true)
        {
            r-=step;
            this.remain;

            var t=Math.min(this.remain, this.maxNum)-step;

            r+=t;
            this.remain-=t+step;

            if(this.remain<=2*step)
                break;
        }

        this.remain=r;
        return true;        
    },
    makeMoves:function(step)
    {
        while(true)
        {
            var result=this.move(step);

            if(!result)
                return;
        }
    }
}
camel.setUp();
camel.makeMoves(1);

We move the the camel 1 step and try to carry all the bananas remained for each turn until it reaches the final position

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...