initial commit

This commit is contained in:
Raphael Martin 2024-01-16 17:23:38 +01:00
parent 6607be1a13
commit f78ef0cd39
2 changed files with 38 additions and 0 deletions

View File

@ -1,2 +1,9 @@
# php_pimebday
## requierments
- php > 7.4
## execute
execute the index.php from your web server

31
index.php Normal file
View File

@ -0,0 +1,31 @@
<?php
function getNextPrimeBdays(int $age, int $countNextBdays,?int $ageLimit = null):array{
if ($ageLimit === null){
$ageLimit = 100;
}
$out = [];
while($countNextBdays > 0) {
for ($age = 32; $age <= $ageLimit; $age++) {
$primenum = true;
for($denominator = 2; $denominator <= $age/2; $denominator++) {
if(((float)$age % (float)$denominator) == 0.0) {
$primenum = false;
break;
}
}
if ((bool)$primenum) {
$out[] = $age;
$countNextBdays--;
if($countNextBdays == 0){
break;
}
}
}
}
return $out;
}
echo json_encode(getNextPrimeBdays(32,10));