Thracian
Thracian

Reputation: 661

Develop an algorithm for a transport puzzle

I am challenged by a co-worker to develop an algorithm for the following puzzle.

There is a bridge that can only hold two trucks at a time. One end of the bridge, there are heavy granite blocks that need to be transported to the other end of the bridge. There are 5 trucks total. Each truck can take up to 5 granite blocks. It takes 10 minutes to load and unload a single block. Regardless of the weight, it takes 1 hr for a truck to travel across the bridge. There is only one person at each end of the bridge who loads and unloads the trucks so a truck needs to wait while another one is being loaded or unloaded.

Our goal is to transport as many blocks as possible in 12 hours. What is the total number of blocks we can transport in this time-frame? Would it help to have more than 5 trucks?

How would you approach this problem and develop an algorithm?

Upvotes: -2

Views: 588

Answers (1)

Nasir Ul Islam Butt
Nasir Ul Islam Butt

Reputation: 121

Break that problem into pieces .
Bridge can hold up 2 trucks at a time .We have 5 trucks . It takes 1 hr for a truck to cross the bridge . for the first hr , 2 trucks will go side by side , they will then wait for unloading 5 *2=10 blocks . Same will happen for the other 2 trucks . For the first 2 hrs , there will be total of 20 blocks being displaced . Meanwhile , last two trucks will be unloaded way before and when the 5th truck is carrying the blocks ,other 1(unloaded) one will be travelling its way back to the loading . So for the 3rd hr ,only 5 blocks will be displaced .But since there another truck waiting at the unloaded channel(for the 4th hr) . IT will start its journey right away, while the "still loading" truck will take 10 mints to refill , so total time taken =1 hr and 10 mints adds up 4 hr 10mins ,total blocks transfer=20.
same will goes on as follows :
5 hr 20 mints :25 blocks
6 hr 30 mints : 30 blocks
7 hr 40 mints : 35 blocks
8 hr 50 mints : 40 blocks
10 hr 00 mints : 45 blocks
11 hr 20 mints : 50 blocks Since, truck takes 1 hr , they will remain in the bridge till the time finishes . So total blocks transferred =50. Sorry for the wrong spellings lad .

Upvotes: 0

Related Questions