Puzzle Details :
The owner of abanana plantation has acamel . He wants to transport his 3000banana s to the market, which is located after the desert. The distance between hisbanana plantation and the market is about 1000 kilometers. So he decided to take hiscamel to carry thebanana s. Thecamel can carry at the maximum of 1000banana s at a time, and it eats onebanana for every kilometer it travels.What is the mostbanana s you can bring over to your destination?
Solution:
First of all, the brute-force approach does not work. If the Camel starts by picking up the 1000 banana s and tries to reach point B, then the camel will eat up all the 1000 banana s on the way and there will be no banana s left for him to return to point A.
So we have to take an approach that the Camel drops the banana s in between and then returns to point A to pick up banana s again.
Since there are 3000 banana s and the Camel can only carry 1000 banana s, he will have to make 3 trips to carry them all to any point in between.
<---p1---><--------p2-----><-----p3---->
A---------------------------------------->B
When banana s are reduced to 2000 then the Camel can shift them to another point in 2 trips and when the number of banana s left is <= 1000, then he should not return and only move forward.
In the first part, P1, to shift the banana s by 1Km, the Camel will have to
- Move forward with 1000
banana s –camel Will eat up 1banana on the way forward - Leave 998
banana after 1 km and return with 1banana –camel will eat up 1banana on the way back - Pick up the next 1000
banana s and move forward –camel Will eat up 1banana on the way forward - Leave 998
banana after 1 km and return with 1banana –camel will eat up 1banana on the way back - Will carry the last 1000
banana s from point a and move forward –camel will eat up 1banana
After point 5 the Camel does not need to return to point A again. So to shift 3000 banana s by 1km, the Camel will eat up 5 banana s. After moving to 200 km the Camel would have eaten up 1000 banana s and is now left with 2000 banana s.
Now in Part P2, the Camel needs to do the following to shift the Banana s by 1km.
- Move forward with 1000
banana s –camel Will eat up 1banana on the way forward - Leave 998
banana after 1 km and return with 1banana –camel will eat up this 1banana on the way back - Pick up the next 1000
banana s and move forward –camel Will eat up 1banana on the way forward
After point 3 the Camel does not need to return to the starting point of P2. So to shift 2000 banana s by 1km, the Camel will eat up 3 banana s. After moving to 333 km the camel would have eaten up 1000 banana s and is now left with the last 1000 banana s.
The Camel will actually be able to cover 333.33 km, I have ignored the decimal part because it will not make a difference in this example.
Hence the length of part P2 is 333 Km.
Now, for the last part, P3, the Camel only has to move forward. He has already covered 533 (200+333) out of 1000 km in Parts P1 & P2. Now he has to cover only 467 km and he has 1000 banana s.
No comments:
Post a Comment