There is a line of lockers numbered 1 to 1024, initially all closed.
James walks down the line, opens locker #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, opens 1020, skips 1018, and so on....).
He continues to walk up and down the line until all the lockers are open.
Which locker did James open last ?
Solution to the Problem:
The last locker that James opens is locker #342.
Look for patterns in the following numbers that are left after each pass.
After the first pass, only even numbered lockers will be closed:
2 4 6 8 10 12 14 ... 1012 1014 1016 1018 1020 1022 1024
After the second pass, the following lockers will still be closed:
2 6 10 14 18 22 26 ... 998 1002 1006 1010 1014 1018 1022
After the third pass, the following lockers will still be closed:
6 14 22 30 38 46 54 ... 982 990 998 1006 1014 1022
After the fourth pass, the following lockers will still be closed:
6 22 38 54 70 86 ... 982 998 1014
After the fifth pass, the following lockers will still be closed:
22 54 86 118 ... 918 950 982 1014
After the sixth pass, the following lockers will still be closed:
22 86 150 214 278 342 ... 726 790 854 918 982
After the seventh pass, the following lockers will still be closed:
86 214 342 470 598 726 854 982
After the eighth pass, the following lockers will still be closed:
86 342 598 854
After the ninth pass, the following lockers will still be closed:
342 854
After the tenth pass, only locker 342 will be closed.
So, on the eleventh and final pass, locker 342 will be opened.
Notice that 1024 is a power of 2, and 1024 = 210.
Here are K. Sengupta's solutions:
(Method 1)
After the first pass we are left with only even numbers 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: [1,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 locker that James opened last must be 342.
(Method II)
Write the labels in binary.
1st pass: James opened those ending in 1, leaving those ending in 0 still closed.
2nd pass: James opened those ending in 00, leaving -10 closed.
3rd pass: James opened 010, leaving -110 closed.
4th pass: James opened -1110, leaving -0110 closed.
5th pass: James opened -00110, leaving -10110 closed.
6th pass: James opened -110110, leaving -010110 closed.
Continuing in this manner, the single locker 0101010110 = 342 wii be left, which will be opened last.
Correctly solved by:
1. Colin (Yowie) Bowey | Beechworth, Victoria, Australia |
2. Ivy Joseph | Pune, Maharashtra, India |
3. Dr. Hari Kishan |
D.N. College, Meerut, Uttar Pradesh, India |
4. Kelly Stubblefield | Mobile, Alabama |
5. Davit Banana | Istanbul, Turkey |
6. Seth Cohen | Concord, New Hampshire |