#!/usr/bin/php = 1); $res = $quad; for ($p=2; $p<=$n; $p++) $res = quad_mul($res, $quad); return $res; } } function quad_is_immortal($quad, $power) { $quadpow = quad_int_power($quad, $power); for ($i=0; $i<4; $i++) { $x1 = bcabs($quad[$i]); $x2 = bcabs($quadpow[$i]); if (substr($x2, -strlen($x1)) != $x1) return false; } return $quadpow; } function _go($a, $b, $c, $d, $power, $distance, &$progr, &$found) { $quad = [$a, $b, $c, $d]; $quadpower = quad_is_immortal($quad, $power); if ($quadpower !== false) { $a_ = $quadpower[0]; $b_ = $quadpower[1]; $c_ = $quadpower[2]; $d_ = $quadpower[3]; if (($c!=0) || ($d!=0)) { $str = "QUAD "; } else if ($b!=0) { $str = "CPLX "; } else { $str = "REAL "; } $str .= "| Distance=$distance | "; $str .= "[$a + $b i + $c j + $d k] ^ $power = [$a_ + $b_ i + $c_ j + $d_ k]"; if (!in_array($str,$found)) { # echo "$str\n"; $found[] = $str; } } #if ($progr++ % 10000 == 0) { # echo "(Dist=$distance) Processing ($a, $b, $c, $d) 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 = [ $str ]; $progr = 0; $a = $distance; for ($b=0; $b<=$distance; $b++) { for ($c=0; $c<=$distance; $c++) { for ($d=0; $d<=$distance; $d++) { if ($d == 0) echo "\r".round(memory_get_usage()/1024/1024, 2)." MiB (".count($found)." found); ($a), $b, $c, $d "; for ($power=2; $power<=MAX_POWER; $power++) { _go($a, $b, $c, $d, $power, $distance, $progr, $found); _go($b, $a, $c, $d, $power, $distance, $progr, $found); _go($b, $c, $a, $d, $power, $distance, $progr, $found); _go($b, $c, $d, $a, $power, $distance, $progr, $found); } } } } file_put_contents(__DIR__.'/result.txt', implode("\n",$found)."\n", FILE_APPEND); file_put_contents(__DIR__.'/savestate.txt', $distance+1); }