Exemple #1
0
            //echo "$now => $next = $len\n";
            $now = $next;
        }
        return $len;
    }
}
$max = [];
$max_num = 0;
$start = time();
//可怜的我发现自己不会写排列组合的代码 >_< ,下一版本改进
for ($path_num = 123456789; $path_num <= 598764321; $path_num++) {
    $str = strval($path_num);
    if ($str[0] == 3) {
        $path_num = 512346789;
        //3,4和1,2等效
    }
    if (strpos($str, '0')) {
        continue;
    }
    $path = array_filter(preg_split("//", $str));
    if (count(array_unique($path)) != count($path)) {
        continue;
    }
    $o = new PathFinder();
    $total = $o->calculate($path);
    if ($total > $max_num) {
        $max_num = $total;
        $max = $path;
    }
}
var_dump($max, $max_num, time() - $start);