Skip to content
Snippets Groups Projects
Commit 27f9b979 authored by vagrant's avatar vagrant
Browse files

php implementation

parent 6c0dde75
No related branches found
No related tags found
No related merge requests found
<?php
function isPrime($num) {
$root = sqrt($num);
if((int) $root == $root ) {
return false;
}
for($i=2;$i<$root;$i++) {
if($num%$i==0) {
return false;
}
}
return true;
}
if(isset($argv[1])) {
$num = $argv[1];
$primes = array();
$i = 0;
while(count($primes) < $num) {
if(isPrime($i)) {
$primes[] = $i;
}
$i++;
}
echo join(",",$primes);
// echo count($primes);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment