help with algorithm

Status
Not open for further replies.

manu2011

Beta member
Messages
3
hello everyone,
please help me with this :

Suppose given two identical crystal balls and n stories building. the goal is to find the least floor so that if you throw the ball from this floor, the ball will break. the rules are:

the two balls break at the same floors.
if a ball breaks at floor i it also breaks at floor i+1.

i have to design the best algorithm to find the least floor the ball breaks at with minimum number of possible ball throws.

thanks
 
I would assume the best way would be to start dropping one ball from n, the other ball from n-(n-1), and run a counter that subtracts a floor from the first ball and moves the second ball to n-(n-2) ...etc. When the condition for one of the ball changes from broken=true to broken=false or vice versa, you would know which floor is the right floor.
 
Status
Not open for further replies.
Back
Top Bottom