Skip to content

Instantly share code, notes, and snippets.

@jl91
Created January 20, 2016 20:55
Show Gist options
  • Save jl91/880346099b4770bed641 to your computer and use it in GitHub Desktop.
Save jl91/880346099b4770bed641 to your computer and use it in GitHub Desktop.
<?php
function generatePrimes($howMany)
{
$numbers = [];
$i = 2;
while (count($numbers) < (int) $howMany) {
for ($j = 2; $j < $i - 1; $j++) {
$rs = ($i % $j === 0);
if ($rs) {
$i++;
continue 2;
}
}
$numbers[] = $i;
$i++;
}
return $numbers;
}
$primes = generatePrimes(10001);
$lastPrime = end($primes);
print_r($lastPrime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment