Skip to content

Instantly share code, notes, and snippets.

@karlmonson
Created October 29, 2015 05:16
Show Gist options
  • Save karlmonson/6b23f08d8883724b6616 to your computer and use it in GitHub Desktop.
Save karlmonson/6b23f08d8883724b6616 to your computer and use it in GitHub Desktop.
<?php
/*
* Locker Problem
* Author: Karl Monson
* URL: https://github.com/karlmonson
* Resource: http://mathforum.org/library/drmath/view/54242.html
*/
$lockers = array();
for($i = 0; $i <= 1000; $i++){
$lockers[$i] = 0;
}
for($x = 1; $x <= 1000; $x++){
for($y = $x; $y <= 1000; $y += $x){
$lockers[$y] = !$lockers[$y];
}
}
foreach($lockers as $key => $value){
if($value == 1){
echo $key . PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment