|
Question:
There are 100 doors in a long hallway. They are all closed. The first time you walk by each door,
you open it. The second time around, you close every second door (since they are all opened).
On the third pass you stop at every third door and open it if it’s closed, close it if it’s open.
On the fourth pass, you take action on every fourth door. You repeat this pattern for 100 passes.
At the end of 100 passes, what doors are opened and what doors are closed?
|
|
Answer:
You can figure out that for any given door, say door #42, you will visit it for every divisor
it has. so 42 has 1 & 42, 2 & 21, 3 & 14, 6 & 7. so on pass 1 i will open the door, pass 2 i will close
it, pass 3 open, pass 6 close, pass 7 open, pass 14 close, pass 21 open, pass 42 close. for every pair
of divisors the door will just end up back in its initial state. so you might think that every door will
end up closed? well what about door #9. 9 has the divisors 1 & 9, 3 & 3. but 3 is repeated because 9 is
a perfect square, so you will only visit door #9, on pass 1, 3, and 9... leaving it open at the end.
only perfect square doors will be open at the end.
|