Originally posted by geepamoogle Hmm, it occurs to me to find the LCM and figure out what portion of those are open and closed. Then figure out how many are left after all the complete runs are done.
Unfortunately, this runs into a little problem in that you have 4,294,967,301 lockers, and an LCM of 5,354,228,880.
However, if you could determine the first 22 boys (LCM=232,792,560 ...[text shortened]... very 23rd locker, it may be more easily solved with a mere 186,737,708 checks for the final run.
Answer available now, so if anyone else gets an answer I'll tell you if you are right. My program took 41 hours to do it! (mucho respect if you can compute the answer quickly!)
Originally posted by geepamoogle Hmm, it occurs to me to find the LCM and figure out what portion of those are open and closed. Then figure out how many are left after all the complete runs are done.
Unfortunately, this runs into a little problem in that you have 4,294,967,301 lockers, and an LCM of 5,354,228,880.
However, if you could determine the first 22 boys (LCM=232,792,560 ...[text shortened]... very 23rd locker, it may be more easily solved with a mere 186,737,708 checks for the final run.
Implementations of programs to solve this need to be a little careful about storing very large arrays. For instance, if a program needs an array of 2^32 booleans (door open / door closed), even if they are packed into 1 bit each (which might hit execution speed), that single array will need about half a gigabyte of RAM.
Originally posted by Palynka So the iamtiger coder defeated the iamtiger code-defeater. Yin and yang.
Yes, sorry about that!
Can anyone solve the following altered problem, which would defeat my code!
'
There are 2^40 pupils in the school, and 2^40 lockers
In turn, each pupil walks down the row of lockers. the first one opening every locker. the second one changing the state of every second locker, the third one changing every third and so on.
How many lockers are open when the exercise completes?
Originally posted by iamatiger Yes, sorry about that!
Can anyone solve the following altered problem, which would defeat my code!
'
There are 2^40 pupils in the school, and 2^40 lockers
In turn, [b]each pupil walks down the row of lockers. the first one opening every locker. the second one changing the state of every second locker, the third one changing every third and so on.
How many lockers are open when the exercise completes?[/b]
That problem, ironically, is far easier to solve. 1,048,576 lockers would be left open.
Originally posted by wormer In a school there are 1000 lockers. The principle of this school takes 4 students. He tells the first one to open every locker, the second one to close every second locker, the third one to open or close every third locker finally the forth one to open or close every forth locker. After these round ups how many lockers will be open?
600!
I did it manually for 10 lockers and got 6 open, 4 closed. I multiplied 6 * 100 = 600.
I did it manually for 10 lockers and got 6 open, 4 closed. I multiplied 6 * 100 = 600.
That's not a bad approximation, but since you know that the LCM of 2,3 and 4 is 12 then you only needed to to it manually for 2 more to get a precise solution.
I just had this math problem in my math class today with just 25 lockers. The answer was 1,4,9,16, and 25. I think it's all the number's with whole numbers as their square roots.