I came across this puzzle, to fill in the blanks so that it solved the math.
_ _ 7 _
x _ 7 _
----------- (x means multiply, it is not a variable)
_ _ _ _ _
_ _ _ 2 _ 0
8 _ 5 _ 0 0
----------- total
_ _ _ _ _ _
So I created a PHP script to brute force it.
I gave it limited parameters and told it to run.
The only problem is it has been running for 2 days without luck. (i think there are like 2 trillion possibilities)
So I am wondering if anyone can improve this script.
Thanks!
<?php
set_time_limit(0);
$start = (float) array_sum(explode(' ', microtime()));
for ($a = 1; $a <= 9; $a++) {
for ($b = 0; $b <= 9; $b++) {
for ($c = 0; $c <= 9; $c++) {
for ($d = 1; $d <= 9; $d++) {
for ($e = 0; $e <= 9; $e++) {
for ($f = 1; $f <= 9; $f++) {
for ($g = 0; $g <= 9; $g++) {
for ($h = 0; $h <= 9; $h++) {
for ($i = 0; $i <= 9; $i++) {
for ($j = 0; $j <= 9; $j++) {
for ($k = 0; $k <= 9; $k++) {
for ($L = 0; $L <= 9; $L++) {
for ($m = 0; $m <= 9; $m++) {
for ($n = 0; $n <= 9; $n++) {
for ($o = 0; $o <= 9; $o++) {
for ($p = 0; $p <= 9; $p++) {
for ($q = 0; $q <= 9; $q++) {
$line1 = $a . $b . "7" . $c;
$line2 = $d . "7" . $e;
// ----------------------------
$line3 = $f . $g . $h . $i . $j;
$line4 = $k . $L . $m . "2" . $o . "0";
$line5 = "8". $p . "5". $q . "0". "0";
$addtotal = $line3 + $line4 + $line5;
$multotal = $line1 * $line2;
if($addtotal == $multotal){
echo $line1 . "\r\n";
echo $line2 . "\r\n";
echo "----------------------------\r\n";
echo $line3 . "\r\n";
echo $line4 . "\r\n";
echo $line5 . "\r\n";
echo "----------------------------\r\n\r\n";
echo $multotal;
$end = (float) array_sum(explode(' ', microtime()));
$perc = ($end-start);
$perc = ($perc / 60);
echo "Proccessing time: " . sprintf("%.4f", ($perc)) . "mins";
exit;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
?>