Given a fleet of 50 trucks, each with a full fuel tank and a range of 100 kms, how far can you deliver a payload? You can transfer the payload from truck to truck, and you can transfer fuel from truck to truck. Assume all the payload will fit in one truck.
Solution
Assumption - trucks have consistent mileage and no loss of fuel in transfer.
a. If you had one truck, the max distance that can be traveled is 100 kms.
b. If you had two trucks, after travelling 50 kms both trucks would be at half fuel tank. Transfer fuel from one truck to other and travel another 100 kms. Total distance is 150 kms.
c. If you had three trucks, after travelling 33.33 kms all three trucks would be at 2/3 fuel tank. Transfer fuel from one truck to other two and travel another 50 kms. Now follow (b) above. Total distance is 33.33 + 150 = 183.33 kms.
d. 4 trucks, 100/4 + (c) above i.e. 25 + 183.33 = 208.33 kms.
e. 50 trucks, 100/50 + 100/49 + 100/48 + ... + 100/3 + 100/2 + 100/1
float distance(int trucks, int maxDistanceOnFullTank)
{
if(trucks == 1)
return maxDistanceOnFullTank;
else
return (float)trucks/maxDistanceOnFullTank + distance(trucks-1, maxDistanceOnFullTank);
}
Solution
Assumption - trucks have consistent mileage and no loss of fuel in transfer.
a. If you had one truck, the max distance that can be traveled is 100 kms.
b. If you had two trucks, after travelling 50 kms both trucks would be at half fuel tank. Transfer fuel from one truck to other and travel another 100 kms. Total distance is 150 kms.
c. If you had three trucks, after travelling 33.33 kms all three trucks would be at 2/3 fuel tank. Transfer fuel from one truck to other two and travel another 50 kms. Now follow (b) above. Total distance is 33.33 + 150 = 183.33 kms.
d. 4 trucks, 100/4 + (c) above i.e. 25 + 183.33 = 208.33 kms.
e. 50 trucks, 100/50 + 100/49 + 100/48 + ... + 100/3 + 100/2 + 100/1
float distance(int trucks, int maxDistanceOnFullTank)
{
if(trucks == 1)
return maxDistanceOnFullTank;
else
return (float)trucks/maxDistanceOnFullTank + distance(trucks-1, maxDistanceOnFullTank);
}