I was recently given the bridge torch problem to solve – so I made this script to solve it in the general case (for small numbers of people).

Short description – 4 people in a cave /on one side of a narrow bridge, can only cross to the other side in groups of max size 2, need a torch. There is only one torch. They cross at the speed of the slowest one. What’s the fastest they can all get out (one can go back with the torch and pick up another one).

My algo could probably be optimised to O(N^2) – I’ll get round to it one of these days.

Leave a Reply

You need to enable GD extension in order to use Simple CAPTCHA.