So You Need the Locker Problem Answer Key

The classic locker problem shows up everywhere in discrete math and introductory programming courses. One hundred lockers, one hundred students, each student toggling lockers based on their number. Most people get the setup right and then fumble the logic. Here is what actually works. When you are checking work, having a reference that shows the full reasoning chain saves time. A plain answer list (1, 4, 9, 16, 25, 36, 49, 64, 81, 100) is fine for a quick glance, but it does not help you understand where someone went wrong. The better answer keys walk through the factor-counting logic, show the toggle simulation, and explain why only perfect squares survive. Each locker gets toggled once per factor of its number. Locker 12, for example, gets touched by students 1, 2, 3, 4, 6, and 12. That is six toggles, which means it ends up closed since it starts closed and an even number of toggles returns it to the original state. Locker 9 gets toggled by students 1, 3, and 9. Three toggles, odd, so it ends up open. The pattern is simple: only lockers with an odd number of factors stay open, and the only numbers with an odd number of factors are perfect squares. That is the entire proof. Square numbers have a repeated factor (the square root), which breaks the usual even-pairing of divisors.

The biggest mistake is assuming the pattern is arbitrary. It is not. Once you recognize that factor count determines the final state, you can extend the problem to any number of lockers and students. The second common error is forgetting that lockers start closed. Some versions phrase it differently, saying the first student opens every locker. If the initial state is open instead of closed, the final open lockers flip to the ones with an even number of factors, which is every non-square number. Always verify the starting condition before applying the answer key. I ran into a tricky edge case while building a auto-grader for an online discrete math class. The instructor had changed the problem to 50 lockers and 50 students but forgot to update the starting state in the problem description. The official answer key listed perfect squares as open, but students who simulated from a closed starting position got the same list, while students who read the slightly ambiguous wording and assumed the first student opened everything ended up with the complements. I wrote a workaround that accepted both answer sets but flagged the ambiguity in the feedback. It cost about two hours to implement the dual-grading logic, but it saved me from a week of email threads.

How to Simulate It Yourself

If you want to verify the answer rather than trust the key, a simulation is straightforward. Initialize an array of one hundred booleans, all false. Loop through each student from one to one hundred, and for each student loop through multiples of their number, flipping the boolean at each position. After all students complete, the indices that are true are your open lockers. In Python this runs in under a second. In a language without booleans, use integers and toggle with modulo arithmetic. The time complexity is O(n log n) because the inner loop runs n/1 plus n/2 plus n/3 and so on, which sums to roughly n times the natural logarithm of n. Below is a link to a clean, printable The Locker Problem Answer Key that includes the full step-by-step reasoning, a toggle table for the standard 100-locker version, and an extended section for variable locker counts. It also covers the closed-to-open starting condition variant. Download The Locker Problem Answer Key (PDF)

Get the Full Details

The 100 locker problem by Lorraine O'Carroll | TPT
The 100 locker problem by Lorraine O'Carroll | TPT

When the Standard Answer Key Fails

The clean perfect-square result only holds for the standard setup. If the problem introduces primes only, or skips certain students, or changes the toggle rule to something like opening on prime multiples, the answer key breaks down immediately. In those cases, you need to revert to simulation. I once saw a professor try to force the standard key onto a variant where every third student locked all lockers divisible by three, which produced a completely different set. It took me about twenty minutes to write a small script that handled the custom rule, compared to the hour I would have spent trying to derive a closed form. If the problem deviates from the classic even-one-toggle-per-factor model, simulate it instead of looking for a formula. Standard 100 lockers, starting closed, each student toggles their multiples: open lockers are perfect squares. Standard 100 lockers, starting open, each student toggles their multiples: open lockers are non-squares. Fifty lockers with the same rules: open lockers are 1, 4, 9, 16, 25, 36, 49. Only the first student opens every locker and everyone else leaves them untouched: all lockers from one to one hundred end up open. These variants show up frequently enough that having a reference table is useful beyond just grading papers. If you are teaching this problem, I recommend making students run the simulation before they see the answer key. It reinforces the connection between factors and toggle count, and it catches the starting-state confusion before it becomes a grading nightmare. The actual answer is easy to memorize, but the reasoning is what matters when the parameters change.