Restructuring

This commit is contained in:
2024-07-01 13:49:44 +00:00
parent f11b705ef0
commit 8d60e1b905
194 changed files with 1296 additions and 112 deletions

View File

@ -0,0 +1,10 @@
title: Find the sum of all numbers that can be written as pandigital products.
url: http://projecteuler.net/problem=32
desc: |
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.
The product 7254 is unusual, as the identity, 39 x 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.
Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
solution: Bruteforce

View File

@ -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;