Created
June 26, 2011 03:18
-
-
Save andersonfraga/1047185 to your computer and use it in GitHub Desktop.
Eratostenes Sieve
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 | |
function eratostenes_sieve($number) { | |
$num_max = floor(sqrt($number)); | |
$list = range(2, $number); | |
for($x = 2; $x <= $num_max; $x++) { | |
foreach($list as $_k => $_val) { | |
if($_val != $x and $_val % $x == 0) { | |
unset($list[$_k]); | |
} | |
} | |
} | |
sort($list); | |
return $list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment