Locker Problem

My first approach to this problem was to start off with a sketch of the lockers after the first 10 students. It looked something like this:
The line represents lockers that are closed and the O represents lockers that are open.

After seeing this table, I thought the solution would be related to prime factorization or prime numbers. This is because the number of time a locker switches depends on how many factors that locker number has. I did not see the pattern, so I decided to create a MATLAB code that would show the results for a set of 100 lockers.

for i=1:100             < Sample size of 100 lockers (This could be increased to 1000, but kept it smaller for now)
   N=i;                       
   K=1:ceil(i);               
   D(i)= length(K(rem(N,K)==0));        <  Finds out how many factors a locker number has
   z=mod(D,2);    < Finds out whether the number of factors is even or odd (z=0 is even, z=1 is odd, remainders!)
   open=find(z==0);           <  Shows which lockers are open
   closed=find(z==1);         <  Shows which lockers are closed
end

After seeing from my code that all the closed ones were 1,4,9,16,25,36,49,64,81, and 100. I finally saw the pattern, all the closed lockers were perfect squares! In hindsight, I probably should have realized the pattern before I started making things complicated with MATLAB code. Then I started to think about why all the closed lockers are perfect squares. If a number has an even amount of factors, for example 2 factors, the locker would close then open (ie. no change). But if you have an odd number of factors, let's take 3, it would go close,open, then close (ie. change). Perfect squares are the only numbers with an odd amount of factors, which is why they are all closed. I definitely feel I made things more complicated than they should have been, but in the end I got the solution!

Comments

Popular posts from this blog

Reflection on Math Art Project

The Dishes Problem

Instrumental vs. Relational