### Brain Teasers

# 100 Closed Lockers

Suppose you're in a hallway lined with 100 closed lockers.

You begin by opening every locker. Then you close every second locker. Then you go to every third locker and open it (if it's closed) or close it (if it's open). Let's call this action toggling a locker. Continue toggling every nth locker on pass number n. After 100 passes, where you toggle only locker #100, how many lockers are open?

You begin by opening every locker. Then you close every second locker. Then you go to every third locker and open it (if it's closed) or close it (if it's open). Let's call this action toggling a locker. Continue toggling every nth locker on pass number n. After 100 passes, where you toggle only locker #100, how many lockers are open?

### Answer

Answer: 10 lockers are left open:Lockers #1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

Each of these numbers are perfect squares. This problem is based on the factors of the locker number.

Each locker is toggled by each factor; for example, locker #40 is toggled on pass number 1, 2, 4, 5, 8, 10, 20, and 40. That's eight toggles: open-closed-open-closed-open-closed-open-closed.

The only way a locker could be left open is if it is toggled an odd number of times. The only numbers with an odd number of factors are the perfect

squares. Thus, the perfect squares are left open.

For example, locker #25 is toggled on pass number 1, 5, and 25 (three toggles): open-closed-open.

Hide Answer Show Answer

## What Next?

View a Similar Brain Teaser...

If you become a registered user you can vote on this brain teaser, keep track of which ones you have seen, and even make your own.

### Solve a Puzzle

## Comments

Maybe this should of gone in math but i liked it

i was thinking all of the primes but you closed all of them in the beghinning. oops.

WOW! I would have had to write it all out and everything...I'm just not that smart.

Great puzzle but surely belongs in the Mathematics category?

Excellent. I worked through the first 20 lockers, noticed that only the perfect squares were open, and realized that those were the only numbers with an odd quantity of factors. I need to eat more fish.

Very Good. It took me a long time to get that one.

Dec 27, 2004

that made my brain hurt

Wow!! I finally got it but now I think I have a headache!!! Great teaser! I agree, though, it should be in the math category!!

this teaser was really hard. it got me goooooood.

The teaser sounded fun at first till i remebered the same exact problem my sophmore son brought home for algebra homework

That really made you think!! alot!! but it was still kewl!

This was an interesting problem although i do agree that it belongs in the math category.

interesting..... unfortunetly I didn't even bother to figure it out!!!!1 How classic of me!!!

very interesting! and a lot of fun

took to long to figure out the answer.... i didnt work it out should go in the math

this is a really great teaser because if you dont have any patients then you will not sit down and work this out. and it really makes you think! i liked it and i got it!!!

I love this teaser. Only problem is, I did this as homework for my math class and it was up to 1,00 lockers...

Whoops. 1000 lockers

LOVE THIS! This will be the first entry into my 'favorite teasers' list.

Easy to figure out when you look for the pattern.

Start with 1, then 2, then 3, then 4, then 5, etc.

You will see the pattern...

using the numbers:

4-1 = 3

9-4 = 5

16-9 = 7

25-16 = 9

36-25 = 11

The pattern, therefore, increases steadily by 2...uncovering the squares

Easy to figure out when you look for the pattern.

Start with 1, then 2, then 3, then 4, then 5, etc.

You will see the pattern...

using the numbers:

4-1 = 3

9-4 = 5

16-9 = 7

25-16 = 9

36-25 = 11

The pattern, therefore, increases steadily by 2...uncovering the squares

Very hard, but extremely fun!

The result depends on what you mean by "every second" locker. I assumed this meant the first, the third, the fifth and so on. "Every third" means no. 1, no. 4, no. 7 and so on. In which case there are only 9 open after 100 passes, their numbers being n^2 + 1 (0

Very easy, but also elegant teaser. The odd number of factors was obvious, and after thinking a moment it was clear that to have an odd number of factors that one of the numbers must be multiplied by itself. Good job!

May 10, 2009

I am unable to understand the logic that why would ALL other numbers have even factors only. I must admit I tried several numbers and came up with even numbers only, but am unable to figure out a logic behind that.

Sep 28, 2011

please help me to understand what this line means,

" Continue toggling every nth locker on pass number n. After 100 passes, where you toggle only locker #100,"

so that I can continue working on this one!

thanks

" Continue toggling every nth locker on pass number n. After 100 passes, where you toggle only locker #100,"

so that I can continue working on this one!

thanks

Oct 12, 2012

Love this brain teaser - one of my favorites to ask during interviews just to see how people think.

Found another great answer here too:

http://www.programmerinterview.com

/index.php/

puzzles/lockers-puzzle/

Found another great answer here too:

http://www.programmerinterview.com

/index.php/

puzzles/lockers-puzzle/

To post a comment, please create an account and sign in.

## Follow Braingle!