More solutions

This commit is contained in:
Jens True 2024-06-28 08:34:07 +00:00
parent 0fbf5ed250
commit 953021438f
3 changed files with 94 additions and 0 deletions

@ -0,0 +1,23 @@
<?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;

@ -0,0 +1,33 @@
<?php
$count = 0;
$sum = 0;
function is_prime(int $n) :bool{for($i=$n**.5|1;$i&&$n%$i--;);return!$i&&$n>1;}
for ($prime = 11; $count < 11; $prime += 2) {
if (is_prime($prime)) {
//echo "Testing $prime\n";
for ($c = 1; $c < strlen($prime); $c++) {
$left = substr($prime, -$c);
//echo "Trimmed left $left\n";
if (!is_prime($left)) {
//echo "Not prime $left\n";
continue 2;
}
}
for ($c = 1; $c < strlen($prime); $c++) {
$right = substr($prime, 0, $c);
//echo "Trimmed right $right\n";
if (!is_prime($right)) {
//echo "Not prime $right\n";
continue 2;
}
}
$sum += $prime;
$count++;
echo "found $prime\n";
}
}
echo "Total sum: $sum\n";

@ -0,0 +1,38 @@
<?php
function pandigital($number)
{
$array = count_chars($number, 1);
ksort($array);
if ($array == array(48=> 1, 49 => 1, 50 => 1, 51 => 1, 52 => 1, 53 => 1, 54 => 1, 55 => 1, 56 => 1, 57 => 1)) {
return true;
} else {
return false;
}
}
$sum = 0;
for ($i = 1023456789; $i < 9876543210; $i++) {
//$i = 1406357289;
if (substr($i, 7, 3) % 17 == 0) {
if (substr($i, 6, 3) % 13 == 0) {
if (substr($i, 5, 3) % 11 == 0) {
if (substr($i, 4, 3) % 7 == 0) {
if (substr($i, 3, 3) % 5 == 0) {
if (substr($i, 2, 3) % 3 == 0) {
if (substr($i, 1, 3) % 2 == 0) {
echo "Close $i\n";
if (pandigital($i)) {
echo "Found: $i\n";
$sum += $i;
}
}
}
}
}
}
}
}
}
echo "Sum: $sum\n";