264 sats \ 8 replies \ @Scroogey 2 Nov \ on: [Daily puzzle] Locker problem science
Lockers 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 are open at the end, all others are closed.
I.e. the square numbers!
Code
I was about to confidently type 1, but I neglected the description about how people needed to open the lockers when they were closed during their turn. Darn it!
reply
I'd love some intuition for this result.
I get that the primes will all be closed, because only the corresponding prime'th student will toggle that locker, but I don't see a clever argument for just the squares being left.
reply
I think the answer is in Why do perfect squares have a odd amount of factors
The squares are exactly those numbers with an odd amount of factors. Because the amount is odd, they are now open.
reply
That makes a ton of sense
reply
Indeed! 👍
reply
There is an intuitive argument. But I'll give it some more time before divulging it.
reply
Fair enough
reply
TIL: a one liner to toggle a variable between values of 0 and 1. Elegant.
a[j] = 1 - a[j]
reply