codingtests/ProjectEuler/032/solve.php
2024-06-28 08:34:07 +00:00

23 lines
570 B
PHP

<?php
function pandigital($number) {
$array = count_chars($number,1);
ksort($array);
if($array == array(49=>1,50=>1,51=>1,52=>1,53=>1,54=>1,55=>1,56=>1,57=>1)) { return true;} else { return false; }
}
$products = [];
for($a = 1; $a <= 2500; $a++) {
for($b = 1; $b <= 2500; $b++) {
$p = $a*$b;
$str = (string)$a.$b.$p;
if(strlen($str) == 9 && pandigital($str))
{
$products[] = $p;
echo "Found $a*$b=$p\n";
}
}
}
$products = array_unique($products);
echo array_sum($products).PHP_EOL;