#!/usr/bin/php = 1); $res = $oct; for ($p=2; $p<=$n; $p++) $res = oct_mul($res, $oct); return $res; } function oct_is_immortal($oct, $power) { $octpow = oct_int_power($oct, $power); for ($i=0; $i<8; $i++) { $x1 = bcabs($oct[$i]); $x2 = bcabs($octpow[$i]); if (substr($x2, -strlen($x1)) != $x1) return false; } return $octpow; } function _go($a, $b, $c, $d, $e, $f, $g, $h, $power, $distance, &$progr, &$found) { $oct = [$a, $b, $c, $d, $e, $f, $g, $h]; $octpower = oct_is_immortal($oct, $power); if ($octpower !== false) { $a_ = $octpower[0]; $b_ = $octpower[1]; $c_ = $octpower[2]; $d_ = $octpower[3]; $e_ = $octpower[4]; $f_ = $octpower[5]; $g_ = $octpower[6]; $h_ = $octpower[7]; if (($e!=0) || ($f!=0) || ($g!=0) || ($h!=0)) { $str = "OCT "; } else if (($c!=0) || ($d!=0)) { $str = "QUAD "; } else if ($b!=0) { $str = "CPLX "; } else { $str = "REAL "; } $str .= "| Distance=$distance | "; $str .= "[$a, $b, $c, $d, $e, $f, $g, $h] ^ $power = [$a_, $b_, $c_, $d_, $e_, $f_, $g_, $h_]"; # if (!in_array($str,$found)) { # echo "$str\n"; # $found[] = $str; file_put_contents('/tmp/daniel_immortal_oct', "$str\n", FILE_APPEND); $found++; # } } #if ($progr++ % 10000 == 0) { # echo "(Dist=$distance) Processing ($a, $b, $c, $d, $e, $f, $g, $h) with power $power \r"; #} } if (file_exists(__DIR__.'/savestate.txt')) { $start_distance = trim(file_get_contents(__DIR__.'/savestate.txt')); } else { $start_distance = 0; } for ($distance=$start_distance; $distance<=MAX_DISTANCE; $distance++) { $str = "--------- Distance: $distance ---------"; echo " \r"; echo "$str\n"; $found = 0; $progr = 0; if (file_exists("/tmp/daniel_immortal_oct")) system("rm /tmp/daniel_immortal_oct"); $a = $distance; for ($b=0; $b<=$distance; $b++) { for ($c=0; $c<=$distance; $c++) { for ($d=0; $d<=$distance; $d++) { for ($e=0; $e<=$distance; $e++) { for ($f=0; $f<=$distance; $f++) { for ($g=0; $g<=$distance; $g++) { for ($h=0; $h<=$distance; $h++) { if ($h == 0) echo "\r".round(memory_get_usage()/1024/1024, 2)." MiB ($found found); ($a), $b, $c, $d, $e, $f, $g, $h "; for ($power=2; $power<=MAX_POWER; $power++) { _go($a, $b, $c, $d, $e, $f, $g, $h, $power, $distance, $progr, $found); _go($b, $a, $c, $d, $e, $f, $g, $h, $power, $distance, $progr, $found); _go($b, $c, $a, $d, $e, $f, $g, $h, $power, $distance, $progr, $found); _go($b, $c, $d, $a, $e, $f, $g, $h, $power, $distance, $progr, $found); _go($b, $c, $d, $e, $a, $f, $g, $h, $power, $distance, $progr, $found); _go($b, $c, $d, $e, $f, $a, $g, $h, $power, $distance, $progr, $found); _go($b, $c, $d, $e, $f, $g, $a, $h, $power, $distance, $progr, $found); _go($b, $c, $d, $e, $f, $g, $h, $a, $power, $distance, $progr, $found); } } } } } } } } # file_put_contents(__DIR__.'/result.txt', "$str\n", FILE_APPEND); # chdir(__DIR__); # system("cat /tmp/daniel_immortal_oct | sort | uniq >> result.txt"); # system("rm /tmp/daniel_immortal_oct"); system("mv /tmp/daniel_immortal_oct result_distance{$distance}_maxpower".MAX_POWER.".txt"); system("sort -us -o result_distance{$distance}_maxpower".MAX_POWER."_unique.txt result_distance{$distance}_maxpower".MAX_POWER.".txt"); file_put_contents(__DIR__.'/savestate.txt', $distance+1); }