时间:2021-07-01 10:21:17 帮助过:17人阅读
ignore_user_abort(true);
set_time_limit(0);
$tmp = array();
function getArr($arr='') {
for ($i = 0; $i <= 11; $i++) {
$arr[] = $i;
if (count($arr) < 8) {
getArr($arr);
}
if ( count($arr) < 8 && count($arr) > 1 ) {
array_pop($arr);
continue;
} elseif ( count($arr) == 1 ) {
unset($arr);
continue;
} elseif ( checkArr($arr) ) {
$GLOBALS['tmp'][] = $arr;
}
}
}
function checkArr($arr)
{
$m = array();
$val = 4;
if ($val == $arr[0] + $arr[1] - 9){
$m[] = $arr[0] + $arr[1] - 9;
}
if ($val == $arr[2] - $arr[3] * $arr[4]) {
$m[] = $arr[2] - $arr[3] * $arr[4];
}
if ($val == $arr[5] + $arr[6] - $arr[7]) {
$m[] = $arr[5] + $arr[6] - $arr[7];
}
if ($arr[5] != 0) {
if ($val == $arr[0] + $arr[2] / $arr[5]) {
$m[] = $arr[0] + $arr[2] / $arr[5];
}
}
if ($val == $arr[1] - $arr[3] * $arr[6]) {
$m[] = $arr[1] - $arr[3] * $arr[6];
}
if ($val == 9 - $arr[4] - $arr[7]) {
$m[] = 9 - $arr[4] - $arr[7];
}
$tmp = array_count_values($m);
foreach ($tmp as $v) {
if ( $v == 6 ) {
return true;
} else {
return false;
}
}
}
$startTime = microtime(true);
getArr();
$endTime = microtime(true);
for( $i=0; $i$arr = $tmp[$i];
echo $str=<<
{$arr[0]} | {$arr[1]} | 9 |
{$arr[2]} | {$arr[3]} | {$arr[4]} |
{$arr[5]} | {$arr[6]} | {$arr[7]} |
set_time_limit(300);
print_r(test());
function test(){
$ret = array();
for($a=0; $a<12; $a++){
for($b=0; $b<12; $b++){
for($c=0; $c<12; $c++){
for($d=0; $d<12; $d++){
for($e=0; $e<12; $e++){
for($f=1; $f<12; $f++){
for($g=0; $g<12; $g++){
for($h=0; $h<12; $h++){
if($a+$b-9==4 && $c-$d*$e==4 && $f+$g-$h==4 && $a+$c/$f==4 && $b-$d*$g==4 && 9-$e-$h==4){
return array(
'a' => $a,
'b' => $b,
'c' => $c,
'd' => $d,
'e' => $e,
'f' => $f,
'g' => $g,
'h' => $h
);
}
}
}
}
}
}
}
}
}
return $ret;
}
?>