RosettaCodeData/Task/Munchausen-numbers/PHP/munchausen-numbers.php
2023-07-01 13:44:08 -04:00

25 lines
416 B
PHP

<?php
$pwr = array_fill(0, 10, 0);
function isMunchhausen($n)
{
global $pwr;
$sm = 0;
$temp = $n;
while ($temp) {
$sm= $sm + $pwr[($temp % 10)];
$temp = (int)($temp / 10);
}
return $sm == $n;
}
for ($i = 0; $i < 10; $i++) {
$pwr[$i] = pow((float)($i), (float)($i));
}
for ($i = 1; $i < 5000 + 1; $i++) {
if (isMunchhausen($i)) {
echo $i . PHP_EOL;
}
}