Compare commits
No commits in common. "d54e53eff9a0c75a636ccf5ea5ff77d2c755b4d9" and "0fbf5ed2507c332de8887a38c2a39805bbb01ad6" have entirely different histories.
d54e53eff9
...
0fbf5ed250
@ -1,23 +0,0 @@
|
|||||||
<?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;
|
|
@ -1,33 +0,0 @@
|
|||||||
<?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";
|
|
@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
//Incredibly slow... Brute force the worse possible way
|
|
||||||
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";
|
|
Loading…
Reference in New Issue
Block a user