Created
October 29, 2015 05:16
-
-
Save karlmonson/6b23f08d8883724b6616 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
<?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