Saturday, December 15, 2007

The Locker Puzzle

This is my favorite puzzle.

A hallway in a school has 100 lockers. A student runs down the hall and opens every locker. A second student runs down the hall and closes every other locker, starting at the second. A third student runs down the hall and "flips" every third locker, starting at the third - if the locker is open, he closes it; if it's closed, he opens it.

A total of 100 students run down the hall, opening and closing lockers. In general, the n-th student flips every n-th locker.

After all 100 students run through the hall, which lockers are open?

Labels: , ,

21 Comments:

Blogger Robert said...

There are (at least) two ways of solving this: brute force, where you imitate the students on paper or by flipping coins, etc, and logically. Extra points for solving it logically.

December 15, 2007 7:29 PM  
Blogger Robert said...

Also: that guess you have in your head? The one that seems to make sense and now you just have to prove it? It's wrong.

December 15, 2007 8:55 PM  
Blogger John Levenstein said...

i'm going to go with brute force

December 15, 2007 11:26 PM  
Blogger John Levenstein said...

but i'm not going to use paper or coins. i'm going to use lockers and students.

December 15, 2007 11:28 PM  
Blogger frank b. said...

What about simplification (which is neither brute force nor logic)? I imagined 4 kids and 4 lockers.

December 16, 2007 5:07 AM  
Blogger John Levenstein said...

i don't have a favorite puzzle.

December 16, 2007 8:35 AM  
Blogger Robert said...

This post has been removed by the author.

December 16, 2007 8:55 AM  
Blogger Robert said...

This post has been removed by the author.

December 16, 2007 8:56 AM  
Blogger Robert said...

Frank, how did you simplify to four without subsequently using brute force or logic?

Also it's only really solved if, once you've solved for 4, you can predict the other ones up to 100 or further.

December 16, 2007 9:25 AM  
Blogger John Levenstein said...

as far as i can tell, frank hasn't accomplished anything yet. all right, i'm going to sneak into a junior high school right now and break this thing wide open.

December 16, 2007 9:55 AM  
Blogger Robert said...

John, a high school hallway or a college gymnasium would work just as well.

Where's Bernie in all this; Bernie with her precious primes?

December 16, 2007 10:03 AM  
Blogger John Levenstein said...

interesting that you mention primes. here's what i've got so far. all primes end up closed, since they start open and will only be closed the one time someone passes through. numbers with even numbers of factors end up closed. odd number of factors is open. i don't know how to take this any further with an n and also maybe an nth and other symbols. but i am closing in on a pattern for the value of pi. i should have it soon. i'll be back in a little bit.

December 16, 2007 10:56 AM  
Blogger Bernie said...

a cursory one-coffee thought in the a.m. leads me away from precious primes, and makes me think perfect squares are the lockers left. clarification anon!

December 16, 2007 11:03 AM  
Blogger John Levenstein said...

i think bernie's right. but, in my defense, it seems only perfect squares have an odd number of factors, since, otherwise, factors come in pairs.

December 16, 2007 11:12 AM  
Blogger Bernie said...

How can robert know the guess in my head is wrong?

December 16, 2007 11:41 AM  
Blogger Robert said...

Yes, it's the perfect squares. Full points to Bernie for figuring it out; full points to John for mentioning the odd number of factors, but with a few points subtracted for bringing pi into it.

Bernie wrote:

  How can robert know the guess in my head is wrong?

Because everyone who knows math at all starts out by thinking it's the prime numbers!

December 16, 2007 12:14 PM  
Blogger Bernie said...

Robert, I found your taunt about primes to be a red herring, and I consequently wasted about six or seven minutes thinking about primes, then realized, this isn't about primes!

December 16, 2007 12:21 PM  
Blogger Robert said...

You would have gone to primes anyway. Trust me.

December 16, 2007 12:23 PM  
Blogger frank b. said...

In my haste to come up with a solving strategy that was neither brute force nor logic, I misread the puzzle.

December 16, 2007 4:35 PM  
Blogger Bernie said...

No way on going to primes. I have a prime number bell it my head. It certainly didn't go off upon reading this.

December 16, 2007 4:56 PM  
Blogger Robert said...

Bernie, I would like to believe you.

December 16, 2007 5:48 PM  

Post a Comment

<< Home