There is a line of lockers numbered 1 to 1024, initially all closed.
A man walks down the line, opens 1, then alternately skips and opens each closed locker (so he opens 1, 3, 5, ... , 1023). At the end of the line he walks back, opens the first closed locker, then alternately skips and opens each closed locker (so he opens 1024, skips 1022 and so on).
He continues to walk up and down the line until all the lockers are open.
Which locker is opened last?
after the first pass we are left with only even number still closed so the number of the lockers still closed can be given by 2t with t>=0 and t<=512. Now the next pass he alternates opening and closing these lockers starting at 1024, so now the lockers left open is given by 1022-4t with t in [0,255]. Now we can notice a pattern that at each step the number of the lockers left closed is in arithmetic progression and the common difference is double the previous one. So the following table lists the progression in t for each step and the range for t
2t [0,512]
1022-4t [0,255]
6+8t [0,127]
1014-16t [0,63]
22+32t [0,31]
982-64t [0,15]
86+128t [0,7]
854-256t [0,3]
342+512t [0,1]
342
and thus the last locker to be closed is 342
|
Posted by Daniel
on 2008-12-20 22:40:55 |