views:

687

answers:

5

Four men have to cross a bridge at night.Any party who crosses, either one or two men, must carry the flashlight with them. The flashlight must be walked back and forth; it cannot be thrown, etc. Each man walks at a different speed. One takes 1 minute to cross, another 2 minutes, another 5, and the last 10 minutes. If two men cross together, they must walk at the slower man's pace. There are no tricks--the men all start on the same side, the flashlight cannot shine a long distance, no one can be carried, etc.

And the question is What's the fastest they can all get across. I am basically looking for some generalized approach to these kind of problem. I was told by my friend, that this can be solved by Fibonacci series, but the solution does not work for all.

Please note this is not a home work.

+6  A: 

17 minutes - this is a classic MS question.

1,2 => 2 minutes passed.
1 retuns => 3 minutes passed.
5,10 => 13 minutes passed.
2 returns => 15 minutes passed.
1,2 => 17 minute passed.

In general the largest problem / slowest people should always be put together, and sufficient trips of the fastest made to be able to bring the light back each time without using a slow resource.

Andrew
Seems your generalized solution works for other input as well .. +1
Ganesh M
I don't think he is looking for 17. More like he is looking about the algo to solve this problem.
Jimmy Chandra
A: 

17 -- a very common question

-> 1-2 = 2
<- 2 = 2
-> 5,10 = 10 (none of them has to return)
<- 1 = 1
-> 1,2 = 2

all on the other side
total = 2+2+10+1+2 = 17

usually people get it as 19 in the first try

Vivek Sharma
Opps. someone already did it, i type slow :D. anyways, the solution is standard and its a very standard puzzle.
Vivek Sharma
Even I know the solution. But looking for a generalized solution for these kind of problems. Anyway good try.
Ganesh M
+11  A: 

There is an entire PDF that solves the general case of this problem (in a formal proof).

Matthew Jones
Thats a very good reference Matthew. Thanks +1
Ganesh M
+4  A: 

I would solve this problem by placing a fake job ad on Dice.com, and then asking this question in the interviews until someone gets it right.

MusiGenesis
I think this was the fastest down-vote I've ever gotten. Awesome!
MusiGenesis
+1. *O(n)* complexity (with *n* the number of interviews, not the number of bridge crossers, unfortunately ;))
Stephan202
@Stephan202: increasing n (interviewees) is a good thing for me, because I look like I'm accomplishing something at work, plus in this economy it's easy to extort candidates and make them pay for lunch and stuff.
MusiGenesis
And another downvote! The gift that keeps on pissing off!
MusiGenesis
+1  A: 

An exhaustive search of all possibilities is simple with such a small problem space. Breadth or depth first would work. It is a simple CS problem.

I prefer the missionary and cannibal problems myself

Tim