Restructuring
This commit is contained in:
38
solutions/ProjectEuler/043/solve.php
Normal file
38
solutions/ProjectEuler/043/solve.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?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";
|
Reference in New Issue
Block a user