Sunday, October 11, 2026

The Locker Problem

The puzzle

A school has 1,000 students and 1,000 lockers, and every locker starts open. Student 1 closes every locker. Student 2 changes every 2nd locker, student 3 changes every 3rd locker, and so on until student 1,000 has had a turn. Which lockers end up open, which end up closed, and why?

How I worked on it

My first thought was honest panic: 1,000 students and 1,000 lockers is far too much to track in my head. So, I did what I would want my students to do and made the problem smaller. I drew ten boxes on paper and acted out the first ten students, crossing and uncrossing as I went. After a few rounds, I noticed that each student only changes lockers that are multiples of their own number. That changed the question. Instead of following students, I could follow a single locker. Locker 12 is changed by students 1, 2, 3, 4, 6 and 12. These are exactly the divisors of 12.

I then took my first wrong turn. Lockers 2, 3, 5 and 7 were all open, so I guessed that the primes stay open. However, locker 6 broke that idea straight away, because it is open but not prime. So, I stopped guessing and made the following table to dig further.

Highlighted (pink) rows are the lockers that end up closed.


The above table shows a clear pattern. The closed lockers are 1, 4, 9 and 16, the perfect squares (1 = 1², 4 = 2², 9 = 3², 16 = 4²). They are also the only lockers changed an odd number of times.

Who changes each locker?

From the table above, we can see that a student changes a locker only when the student's number divides the locker number exactly. In other words, the students who affect a locker are the factors of that locker number.

Why are perfect squares different?

Let us take an example of locker 16.

The factors of 16 are 1, 2, 4, 8 and 16.

We can pair 1 × 16 and 2 × 8, but the middle factor is 4 × 4.

Because 4 pairs with itself, locker 16 has 5 factors, an odd number. An odd number of changes makes a locker that started open finish CLOSED.

This is the key idea: most numbers have factors in pairs, but a perfect square has one unpaired factor — its square root. Therefore, only perfect-square lockers have an odd number of factors.

Now, I will find all perfect squares up to 1,000

We need the square numbers from 1² upward. As a simple estimate, 30² = 900; so, 31² = 961, but 32² = 1,024; there are exactly 31 perfect squares between 1 and 1,000.

1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961.

Why it works

Each locker starts open, so an even number of changes brings it back to open, and an odd number leaves it closed. The real question is therefore: which numbers have an odd number of divisors? Divisors usually come in pairs. For 12, these are 1 × 12, 2 × 6 and 3 × 4, giving six divisors, an even number. However, a perfect square breaks the pattern because one divisor pairs with itself. For 16, the pairs are 1 × 16, 2 × 8 and then 4 × 4, where the 4 is counted only once. That leaves an odd number of divisors, five.

Answer: The 31 perfect-square lockers (1, 4, 9, 16, … 961) are closed, and the other 969 (1,000 – 31) lockers are open. There are 31 because 31² = 961 is the largest perfect square below 1,000, since 32² = 1,024 is too big. I also checked this by simulating all 1,000 students with a short computer program.

Final Answer

Number of Closed lockers: the 31 perfect-square lockers listed above.

Number of Open lockers: 1,000 − 31 = 969.

Why?

Non-square numbers have factors in pairs, so they are changed an even number of times and finish OPEN. Perfect squares have an odd number of factors because their square root is paired with itself, so they are changed an odd number of times and finish CLOSED.

Taking it into the classroom

I would not start with numbers. I would start by acting it out, with 20 students standing in a row, each holding a card showing “open” on one side and “closed” on the other, while other students take turns flipping them. A physical experience makes the pattern something students see before they can explain it. From there, a few extension questions can lead them deeper into number theory:

  • Which lockers are changed exactly twice? These are the primes, so students arrive at a definition of prime numbers through their own work.
  • Which lockers are changed exactly three times? These are the squares of primes, such as 4, 9, 25 and 49. Why can no other number have exactly three divisors?
  • What if the lockers started closed? What if only students 1 to 500 take a turn? Changing one condition and predicting the result before testing it is where real understanding shows.
  • Can you prove it? Explaining the divisor-pairing argument to a partner, in words or with a picture, is a first step into mathematical proof.

What I am taking away

What I value most about this problem is that it rewards curiosity more than speed. My first strategies were small cases, drawing, a table and a wrong conjecture that I had to give up. These are not signs of weakness. They are what doing mathematics actually looks like. In many of my own school experiences, the steps towards an answer were hidden, and only the final answer counted. With problems like this one, I want my students to see that a crossed-out guess is part of the work, not a failure. The lockers are simply a way in. What I hope my students take with them is the habit of asking, “Why does this pattern happen?”

Another takeaway: One small detail surprised me. In the usual version of this puzzle, the lockers start closed, so the squares are the ones left open. Here the starting state is reversed, so does the answer. The maths is identical, but a student who has memorized “the squares are open” would get this question wrong. This is Skemp’s instrumental vs. relational understanding in a single puzzle. Only the student who knows why the squares behave differently can adapt to the change.



 



No comments:

Post a Comment

More Top Math Films Review

Anthony Persico’s Mashup Math list, “10 Best Math Movies for All Ages,” suggests these films as a break from tests or some Friday fun. I thi...