Last active
May 3, 2018 02:52
-
-
Save FishOfPrey/002131a94d6edcce99b20df29c821c42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<boolean> lockers = new List<boolean>(); | |
for(integer s = 0; s< 1000; s++){ | |
for (integer i = s; i < 1000; i += (s+1)){ | |
if(s == 0) { | |
// First Student Opens every locker | |
lockers.add(true); | |
} else { | |
// nth student toggles every nth locker | |
lockers[i] = !lockers[i]; | |
} | |
} | |
} | |
for (integer i = 0; i < 100; i++) { | |
System.debug((i+1) + ': ' + (lockers[i]?'🚪 (open)':'_ (Closed)')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brute force maths for https://twitter.com/FishOfPrey/status/991860727769018368