100 Closed Lockers
Math brain teasers require computations to solve.
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?
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: openclosedopenclosedopenclosedopenclosed.
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): openclosedopen.
Hide
Comments
dragon6786
Oct 29, 2002
 Maybe this should of gone in math but i liked it 
speedyg1000
Dec 12, 2002
 i was thinking all of the primes but you closed all of them in the beghinning. oops. 
zangel3000
Jun 21, 2003
 WOW! I would have had to write it all out and everything...I'm just not that smart. 
jimbo
Aug 08, 2003
 Great puzzle but surely belongs in the Mathematics category? 
cnmne
Jun 27, 2004
 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. 
knbrain
Dec 27, 2004
 Very Good. It took me a long time to get that one. 
(user deleted)
Dec 27, 2004
 that made my brain hurt 
besbball917
Dec 27, 2004
 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!! 
joeschmmoo
Dec 27, 2004
 this teaser was really hard. it got me goooooood. 
smar_tass
Dec 27, 2004
 The teaser sounded fun at first till i remebered the same exact problem my sophmore son brought home for algebra homework 
surfgrl999
Dec 27, 2004
 That really made you think!! alot!! but it was still kewl! 
babygirl35
Dec 27, 2004
 This was an interesting problem although i do agree that it belongs in the math category. 
stewartfreak20
Dec 27, 2004
 interesting..... unfortunetly I didn't even bother to figure it out!!!!1 How classic of me!!! 
ahurley
Dec 28, 2004
 very interesting! and a lot of fun 
sweetpeao4o3
Dec 28, 2004
 took to long to figure out the answer.... i didnt work it out should go in the math 
brandynicole89
Feb 22, 2005
 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!!! 
thepianistalex
Feb 08, 2006
 I love this teaser. Only problem is, I did this as homework for my math class and it was up to 1,00 lockers... 
thepianistalex
Feb 08, 2006
 Whoops. 1000 lockers 
Smudge
Jun 22, 2006
 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:
41 = 3
94 = 5
169 = 7
2516 = 9
3625 = 11
The pattern, therefore, increases steadily by 2...uncovering the squares 
eyenowhour
Dec 18, 2006
 Very hard, but extremely fun! 
Ildhund
Aug 21, 2007
 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 
javaguru
Jan 03, 2009
 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! 
(user deleted)
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. 
fairygrrrl
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 
jporter892
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/lockerspuzzle/ 
Back to Top
 

Follow Braingle!