Imagine a row of 100 closed doors. Now, make 100 passes along the row, and at each pass "toggle" the doors whose number is divisible by the number of the pass. (
By "toggle", we mean to open a closed door, or close an opened one.)
For example, on the first pass, we will toggle all the doors, on the second, we will toggle only the evennumbered doors, on the third  only doors whose number is divisible by three, and so on.
At the end of the 100 passes, how many doors will be left open?
(from techInterview.org)
Each door will remain the same after your count passes the number of that door. For example, door 1 will only be opened once. So at the end, door 1 = Open
All primes (above one) will open and close exactly once. At the end, all of the prime number doors = Closed. There are 25 primes below 100.
So far we have confirmed: 1 Open, 25 closed. After manually confirming 312 I have 33 open and 33 closed. I believe the final answer will be:
1 open
99 closed

Posted by Dominic
on 20020501 10:43:07 