<?php
function isPrimeNumber($num) {
$isPrime = 1;
for ($i = 2; $i <= ($num/2); $i++) {
if ($num % $i == 0){
$isPrime = 0;
break;
}
}
return ($isPrime==1 || $num==2)? 1 : 0;
}
function generateRightTriangle( $rows ) {
define("END", 47);
for ($i = 1, $count = END; $i <= $rows; $i++) {
for ($j = 5; $j >= $i; $j--) {
while( !isPrimeNumber($count) ){
$count--;
}
if ($count == 3) {
printf("%2d",$count);
}
else
{
printf("%d ",$count);
}
$count--;
}
printf("\n");
}
return true;
}
if (!generateRightTriangle(5)) {
trigger_error("An error has occurred!");
}
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- 47 43 41 37 31
29 23 19 17
13 11 7
5 3
2
preferences:
136.01 ms | 403 KiB | 212 Q