• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Math Challenge

midwestfisherman

Diamond Member
Just wondering if anyone can solve this problem...

Imagine you are at a school that still has student lockers. There are 1000 lockers, all shut and unlocked, and 1000 students.

Here's the problem:

1. Suppose the first student goes along the row and opens every locker.

The second student then goes along and shuts every locker divisible by the number 2.

1. The third student changes the state of every third locker divisible by the number 3. (If the locker is open the student shuts it, and if the locker is closed the student opens it.)

2. The fourth student changes the state of every fourth locker divisible by the number 4.

Imagine that this continues until the thousand students have followed the pattern with the thousand lockers. At the end, which lockers will be open and which will be closed? Why?

Good luck! 😀
 
Originally posted by: minendo
Only the first one.

No way.

Look at locker number 4 for example:

Opened by student one
Closed by student two
Opened by student four.

So it won't just be the first one.
 
Originally posted by: opticalmace
Originally posted by: minendo
Only the first one.

No way.

Look at locker number 4 for example:

Opened by student one
Closed by student two
Opened by student four.

So it won't just be the first one.
Yeah, just noticed that. Missed the part about it being opened if closed.

😱
 
Originally posted by: minendo
Originally posted by: opticalmace
Originally posted by: minendo
Only the first one.

No way.

Look at locker number 4 for example:

Opened by student one
Closed by student two
Opened by student four.

So it won't just be the first one.
Yeah, just noticed that. Missed the part about it being opened if closed.

😱

Hehe. :beer: anyway. 😀
 
Originally posted by: midwestfisherman
Just wondering if anyone can solve this problem...

Imagine you are at a school that still has student lockers. There are 1000 lockers, all shut and unlocked, and 1000 students.

Here's the problem:

1. Suppose the first student goes along the row and opens every locker.

The second student then goes along and shuts every locker divisible by the number 2.

1. The third student changes the state of every third locker divisible by the number 3. (If the locker is open the student shuts it, and if the locker is closed the student opens it.)

2. The fourth student changes the state of every fourth locker divisible by the number 4.

Imagine that this continues until the thousand students have followed the pattern with the thousand lockers. At the end, which lockers will be open and which will be closed? Why?

Good luck! 😀

I'm pretty sure the prime numbered ones will be open. As for the rest, I'm not completely sure. Little bit sleep still.
 
Originally posted by: marquee
Originally posted by: minendo
I think I have it now.

All perfect squares?

beat ya to it, i win 😉

Certain ones can be changed more than once. E.g. 2^2 = 4^1. The prime ones aren't touched except for the first time through. The primes p^p every pth time will be closed since they are changed once more. This problem has something to do with the prime divisors, but since the numbers n^n are only changed every nth time, it puts a very interesting spin on things.
 
These number lockers will be opened:
1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961

Why?

#!/usr/bin/perl

# Create a list of lockers
my @locker_states;

#Start them out all closed
for(my $ii = 0; $ii < 1000; $ii++){
$locker_states[$ii] = "closed";
}

# Have each student open or close lockers.
for(my $ii = 0; $ii < 1000; $ii++){ # $ii <- person number
for(my $jj = 0; $jj < 1000; $jj++){ # $jj <- locker number

if((($jj+1) % ($ii+1)) == 0){
# Switch states.
if($locker_states[$jj] eq "closed"){
$locker_states[$jj] = "opened";
}
elsif($locker_states[$jj] eq "opened"){
$locker_states[$jj] = "closed";
}
}

}
}

# Print a list of all opened lockers.
for(my $ii = 0; $ii < 1000; $ii++){
if($locker_states[$ii] eq "opened"){
print $ii + 1, ", ";
}
}
 
Originally posted by: notfred
These number lockers will be opened:
1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961

Why?

#!/usr/bin/perl

# Create a list of lockers
my @locker_states;

#Start them out all closed
for(my $ii = 0; $ii < 1000; $ii++){
$locker_states[$ii] = "closed";
}

# Have each student open or close lockers.
for(my $ii = 0; $ii < 1000; $ii++){ # $ii <- person number
for(my $jj = 0; $jj < 1000; $jj++){ # $jj <- locker number

if((($jj+1) % ($ii+1)) == 0){
# Switch states.
if($locker_states[$jj] eq "closed"){
$locker_states[$jj] = "opened";
}
elsif($locker_states[$jj] eq "opened"){
$locker_states[$jj] = "closed";
}
}

}
}

# Print a list of all opened lockers.
for(my $ii = 0; $ii < 1000; $ii++){
if($locker_states[$ii] eq "opened"){
print $ii + 1, ", ";
}
}

And this is why one day programmers will rule the earth 🙂
 
Originally posted by: upsciLLion
Originally posted by: marquee
Originally posted by: minendo
I think I have it now.

All perfect squares?

beat ya to it, i win 😉

Certain ones can be changed more than once. E.g. 2^2 = 4^1. The prime ones aren't touched except for the first time through. The primes p^p every pth time will be closed since they are changed once more. This problem has something to do with the prime divisors, but since the numbers n^n are only changed every nth time, it puts a very interesting spin on things.

i dont think it has anything to do with primes. and if you check notfred's results, you'll see they're indeed all the perfect squares
 
Here's scientific explanation of notfreds result:

Every value is divisible by even set of numbers. 24 = 24 * 1, 24 = 12 * 2, 24 = 6 * 4, 24 = 8 * 3. Every break down has two values, and hence their sum will be even. So every number's state will be changed even number of times, and thus remain unchanged. The exception being perfect squares, since they'll have one breakdown where the number repeats: 25 = 5 * 5. We can count 5 only once. Hence those lockers will change their state at the end of the procedure. Hope this makes sense.
 
Every locker will be open because of step 1.
All of the lockers are unnumbered and only step 1 has an effect.
 
U sure that's correct? Locker #16 is opened by student 1, shut by student 2, and then not touched again.
 
Originally posted by: przero
U sure that's correct? Locker #16 is opened by student 1, shut by student 2, and then not touched again.
Wrong. Student 4 would touch it, as would student 8, and student 16.

 
Back
Top