Skip to content

Instantly share code, notes, and snippets.

@FishOfPrey
Last active May 3, 2018 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FishOfPrey/002131a94d6edcce99b20df29c821c42 to your computer and use it in GitHub Desktop.
Save FishOfPrey/002131a94d6edcce99b20df29c821c42 to your computer and use it in GitHub Desktop.
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)'));
}
@FishOfPrey
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment