Camel and Bananas Puzzle

The owner of a banana plantation has a camel. He wants to transport his 3000 bananas to the market, which is located in the desert. The distance between his banana plantation and the market is about 1000 kilometer. So he decided to take his camel to carry the bananas. The camel can carry at the maximum of 1000 bananas at a time, and it eats one banana for every kilometer it travels.

What are the most bananas you can bring over to your destination?





Solution:

In the first part, P1, to shift the bananas by 1Km, the Camel will have to
Move forward with 1000 bananas – Will eat up 1 banana on the way forward
Leave 998 banana after 1 km and return with 1 banana – will eat up 1 banana on the way back
Pick up the next 1000 bananas and move forward – Will eat up 1 banana on the way forward
Leave 998 banana after 1 km and return with 1 banana – will eat up 1 banana on the way back
Will carry the last 1000 bananas from point a and move forward – will eat up 1 banana

Note: After point 5 the Camel does not need to return to point A again.

So to shift 3000 bananas by 1km, the Camel will eat up 5 bananas.

n - 5k = 2000 // n is number of km till now

3000 - 5k = 2000 

k = 1000/5 = 200

After moving to 200 km the Camel would have eaten up 1000 bananas and is now left with 2000 bananas.

Now in the Part P2, the Camel needs to do the following to shift the Bananas by 1km.
Move forward with 1000 bananas – Will eat up 1 banana on the way forward
Leave 998 banana after 1 km and return with 1 banana – will eat up this 1 banana on the way back
Pick up the next 1000 bananas and move forward – Will eat up 1 banana on the way forward

Note: After point 3 the Camel does not need to return to the starting point of P2.

So to shift 2000 bananas by 1km, the Camel will eat up 3 bananas.

n - 3k = 1000

2000- 3k = 1000 

k = 333.33

means after 333 km it will eat 999 bananas and had 1001 banana. now take 1000 bananas and left 1

total distance till now 333 + 200 = 533

banana remaining on camel = 1000

total distance remaining 1000-533 = 467 

final banana remaining = 1000 - 467 = 533

He will eat up 467 bananas on the way forward, and at point B the Camel will be left with only 533 Bananas.

Comments

  1. awk '
    function market(apples, mileage) {
    trips = apples/1000*2-1
    #print trips, apples, mileage
    left = mileage
    while (trips > 1)
    {
    this = 1000 / trips
    #print this
    trips = trips - 2
    left -= this
    }
    return 1000-left;
    }
    BEGIN {
    print "3000 apples in 1000 miles", market(3000, 1000)
    print "5000 apples in 1500 miles", market(5000, 1500)
    }'

    $ sh GC83DPP.sh
    3000 apples in 1000 miles 533.333
    5000 apples in 1500 miles 287.302

    ReplyDelete
  2. After a long time of searching for a recovery expert and platforms to help me recovering my funds, I finally meet a ethical hacker who helped me to recovery all i have lost to this broker site 24options worth $30 Thoushand USD, and I must say that he's a God sent, His help was quite outstanding from the handling of the case by the case manager to completion. I just want to say thank you onlineghosthacker247 for this rare opportunity to get my funds back when all hope seems lost due to the sea of scams out there. I totally recommed him and you can reach him on his email ( onlineghosthacker247 @ gmail . com) and thank me later .

    ReplyDelete

Post a Comment