More Puzzles

   Log inLog in 
 RegisterRegister Immediately 

Difficult Logic Problems
Flipping lockers

Thu Jan 17, 2013 11:34 pm  by tartle

A high school has a strange principal. On the first day, he has his students perform an odd opening day ceremony:

There are one thousand lockers and one thousand students in the school. The principal asks the first student to go to every locker and open it. Then he has the second student go to every second locker and close it. The third goes to every third locker and, if it is closed, he opens it, and if it is open, he closes it. The fourth student does this to every fourth locker, and so on. After the process is completed with the thousandth student, how many lockers are open?
Fri Feb 15, 2013 6:15 am  by Doxic

The amount of prime numbers, not including 1 or 2, but including 4?
Because all others are closed again?
Tue Apr 30, 2013 4:38 am  by Genesisfactor

I may have messed up in the python programming, but i'll venture a solution of 31(i couldn't solve it in my head, but I wanted an answer, sorry :( ). It assumes you don't touch the first locker again, otherwise the answer is 30.

Please edit if wrong

[code:1]import numpy as np
a = np.zeros(1000) #array of locker container
for i in range(1,1001): #these are the students, 1000 of them
for m in range (0,1000): #these are the locker number index
if ((m+1)%i == 0): #this makes it so that the ith student manipulates every ith locker
a[m]= (a[m]+1)%2 #this switches locker states from open to closed
print a #prints the lockers
print np.sum(a) #this adds up all the elements of the array, or all the open lockers, which have a value of 1, otherwise are 0.[/code:1]

also, the array has an interesting pattern of 2,4,6,8....etc 0 between each 1. So, elements 1, 4, 9, 16... are 1s....which once you get that pattern, you can solve it pretty quickly...ish....
Sat Jun 08, 2013 1:59 pm  by Shrey Z

Well,through some experiments on first few lockers we find out that only those lockers are open who have odd no. of factors.i.e Prime numbers therefore 31 lockers will be open. :D
Tue Jun 11, 2013 4:23 am  by aqulaguna

hi all by the way the answer is 31 using c++


int main()
int t(1000),hasil(0);
for(int x=1;x<=1000;x++)
int cek(0);
for(int i=1;i<=x;i++)if(x%i==0)cek++;
if(cek & 1)hasil++;
Fri Jun 21, 2013 5:37 am  by apoorv2904

lets consider a number X
the persons who visit are all the factors of X and X himself ( I am excluding 1 as a factor)
Now the box X was initially open . lets say factor of X are X1,X2,X3,X4,....Xn and finally X arranged in increasing order.
X1 flips and closes X on its visit , X2 opens it X3 closes it ...As can be seen if n is odd Xn will close it and X will open it in its turn .
Thus for a box to be open the number of factors of X must be odd beside it self.

Now lets say a number X is split as multiple of prime numbers as
P denotes a prime number
P1 is 1st prime number
P2 is 2nd and Pn is nth prime number

lets say
X = (P1^a) * ( P2^b) * (P3^c) ... (Pn ^ g )

Total factors of X including 1 and X = (a+1) * (b+1) *(c+1) *....(g+1)

Thus for a box to be open the number of factors of X must be odd beside it self.
This implies [ (a+1) * (b+1) *(c+1) *....(g+1) - 2 ] must be odd.

9 = 3^2
Total factors = 2+1 = 3
3-2 = 1 (odd) hence 9 will be open.
factors 1,3,9 factors beside 1 and 9 are 3

81 = 3^4
Total factors = 4+1 = 5
5-2 = 3 (odd) hence 81 will be open.
factors = 1,3,9,27,81 factors beside 1 and 9 are 3,9,27

36 = (3^2) * (2^2)
Total factors = 4+1 = 5
5-2 = 3 (odd) hence 36 will be open.
factors = 1,2,3,4,6,9,12,18,36 factors beside 1 and 36 are 2,3,4,6,9,12,18
Thu Aug 01, 2013 9:05 pm  by pezzo

All lockers start closed.

If a locker has an even number of visits, it will remain closed when the whole process is over (o,C,o,C,o,C etc). If it has an odd number of visits it will be open at the end of the ritual (O,c,O,c,O...).

Each locker will be visited by students having a number which is a factor of that locker's number. So locker number 12 will be visited by students 1,2,3,4,6 and 12, which makes 6 visits (and locker 12 remains closed).

Factors come in sets of two. So 6 = 1x6 and 2x3. 13 = 1x13. In both cases, even though 13 is a prime, there is an even total of distinct, different factors for 6 and 13 (4 for 6, 2 for 13).

So an open locker will have to have an odd number of visitors, which means it will have an odd number of distinct factors. This is only possible (since factors come in pairs) when a factor is repeated. The only numbers with repeated factors are square numbers: 9=3x3 (only 1 distinct factor); 16 = 1x16, 2x8, 4x4 (5 distinct factors).

Therefore, since there is only one student numbered 4, locker 16 will be visited by students 1, 2, 4, 8 and 16, which is an odd number of students, and the locker will remain open at the end of the ritual.

Since 31x31=961, the highest square root we can find less than 1000 is 31. So there must be 31 square numbers from 1 to 1000.

So 31 students will have left a locker open when the ceremony is done.

So the answer is 31 lockers (those with square numbers) will remain open.

Thu Aug 01, 2013 9:13 pm  by pezzo

"Since 31x31=961, the highest square root we can find less than 1000 is 31."

Sorry. That should read " the highest square root giving a square less than 1000"

Wed Sep 18, 2013 10:22 am  by fadhlarnold



1 2 3 4 5 6 7 8 9 10
O O O O O O O O O O all lockers are open
c c c c c every second locker is closed
c c c every third locker becomes close
O O every fouth locker becomes open

count= every second locker is closed - 5 c's = 500 lockers
count= every third locker becomes close - 3 c's = 300 lockers
count= every 4th locker becomes open 2o's= 200 lockers
500+ 300+ 200 =1000 lockers
200 lockers are open plus the first locker that did not change its open status at any time
Reply to topic
      All times are GMT
Page 1 of 1


Discussion Board Forum Index