Skip to content

Instantly share code, notes, and snippets.

@andersonfraga
Created June 26, 2011 03:18
Show Gist options
  • Save andersonfraga/1047185 to your computer and use it in GitHub Desktop.
Save andersonfraga/1047185 to your computer and use it in GitHub Desktop.
Eratostenes Sieve
<?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