XTaylorSpenceX

Phoenix Prime Calculator v1.0CA

Sep 18th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 39.25 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>The Prime Decider - Phoenix Edition</title>
  7.     <style>
  8.         * {
  9.             margin: 0;
  10.             padding: 0;
  11.             box-sizing: border-box;
  12.         }
  13.  
  14.         body {
  15.             font-family: 'Courier New', monospace;
  16.             background: linear-gradient(135deg, #0a0a0a 0%, #1a0033 50%, #330066 100%);
  17.             color: #00ff88;
  18.             min-height: 100vh;
  19.             display: flex;
  20.             justify-content: center;
  21.             align-items: center;
  22.             overflow: hidden;
  23.             position: relative;
  24.         }
  25.  
  26.         body::before {
  27.             content: '';
  28.             position: absolute;
  29.             width: 200%;
  30.             height: 200%;
  31.             background:
  32.                 radial-gradient(circle at 20% 80%, rgba(255, 100, 0, 0.15) 0%, transparent 50%),
  33.                 radial-gradient(circle at 80% 20%, rgba(255, 200, 0, 0.15) 0%, transparent 50%),
  34.                 radial-gradient(circle at 40% 40%, rgba(255, 50, 0, 0.1) 0%, transparent 50%);
  35.             animation: phoenixFloat 25s ease-in-out infinite;
  36.         }
  37.  
  38.         @keyframes phoenixFloat {
  39.             0%, 100% { transform: translate(0, 0) rotate(0deg) scale(1); }
  40.             25% { transform: translate(-30px, -30px) rotate(90deg) scale(1.1); }
  41.             50% { transform: translate(30px, -50px) rotate(180deg) scale(0.95); }
  42.             75% { transform: translate(-20px, 20px) rotate(270deg) scale(1.05); }
  43.         }
  44.  
  45.         .phoenix-particles {
  46.             position: absolute;
  47.             width: 100%;
  48.             height: 100%;
  49.             overflow: hidden;
  50.             pointer-events: none;
  51.         }
  52.  
  53.         .phoenix-particle {
  54.             position: absolute;
  55.             width: 4px;
  56.             height: 4px;
  57.             background: radial-gradient(circle, rgba(255, 150, 0, 0.8), transparent);
  58.             animation: rise 4s linear infinite;
  59.         }
  60.  
  61.         @keyframes rise {
  62.             0% {
  63.                 transform: translateY(100vh) scale(0);
  64.                 opacity: 0;
  65.             }
  66.             10% {
  67.                 opacity: 1;
  68.             }
  69.             90% {
  70.                 opacity: 1;
  71.             }
  72.             100% {
  73.                 transform: translateY(-100vh) scale(1.5);
  74.                 opacity: 0;
  75.             }
  76.         }
  77.  
  78.         .container {
  79.             background: rgba(10, 10, 30, 0.95);
  80.             border-radius: 20px;
  81.             padding: 30px;
  82.             box-shadow:
  83.                 0 0 100px rgba(255, 100, 0, 0.3),
  84.                 inset 0 0 50px rgba(255, 150, 0, 0.1);
  85.             border: 2px solid rgba(255, 100, 0, 0.4);
  86.             max-width: 1200px;
  87.             width: 95%;
  88.             position: relative;
  89.             z-index: 10;
  90.             display: grid;
  91.             grid-template-columns: 1fr 400px;
  92.             gap: 30px;
  93.             max-height: 90vh;
  94.             overflow: hidden;
  95.         }
  96.  
  97.         .main-panel {
  98.             display: flex;
  99.             flex-direction: column;
  100.             gap: 20px;
  101.         }
  102.  
  103.         h1 {
  104.             text-align: center;
  105.             font-size: 2.2em;
  106.             text-shadow:
  107.                 0 0 20px #ff6600,
  108.                 0 0 40px #ff3300,
  109.                 0 0 60px #ff0000;
  110.             animation: phoenixPulse 3s ease-in-out infinite;
  111.             background: linear-gradient(45deg, #ff6600, #ffaa00, #ff3300);
  112.             -webkit-background-clip: text;
  113.             -webkit-text-fill-color: transparent;
  114.             background-clip: text;
  115.         }
  116.  
  117.         @keyframes phoenixPulse {
  118.             0%, 100% { filter: brightness(1); transform: scale(1); }
  119.             50% { filter: brightness(1.3); transform: scale(1.02); }
  120.         }
  121.  
  122.         .terminal-container {
  123.             background: #000000;
  124.             border: 2px solid rgba(255, 100, 0, 0.5);
  125.             border-radius: 10px;
  126.             padding: 15px;
  127.             display: flex;
  128.             flex-direction: column;
  129.             height: calc(90vh - 60px);
  130.             box-shadow:
  131.                 inset 0 0 20px rgba(255, 100, 0, 0.2),
  132.                 0 0 30px rgba(255, 100, 0, 0.1);
  133.         }
  134.  
  135.         .terminal-header {
  136.             display: flex;
  137.             justify-content: space-between;
  138.             align-items: center;
  139.             padding-bottom: 10px;
  140.             border-bottom: 1px solid rgba(255, 100, 0, 0.3);
  141.             margin-bottom: 10px;
  142.         }
  143.  
  144.         .terminal-title {
  145.             color: #ffaa00;
  146.             font-size: 1.1em;
  147.             text-shadow: 0 0 10px rgba(255, 150, 0, 0.5);
  148.         }
  149.  
  150.         .terminal-controls {
  151.             display: flex;
  152.             gap: 10px;
  153.         }
  154.  
  155.         .terminal-btn {
  156.             padding: 5px 12px;
  157.             font-size: 0.85em;
  158.             background: linear-gradient(135deg, #ff6600, #ff9900);
  159.             color: #000;
  160.             border: none;
  161.             border-radius: 5px;
  162.             cursor: pointer;
  163.             font-weight: bold;
  164.             transition: all 0.3s ease;
  165.         }
  166.  
  167.         .terminal-btn:hover {
  168.             transform: translateY(-2px);
  169.             box-shadow: 0 5px 15px rgba(255, 100, 0, 0.4);
  170.         }
  171.  
  172.         .terminal-output {
  173.             flex: 1;
  174.             background: #0a0a0a;
  175.             padding: 10px;
  176.             overflow-y: auto;
  177.             font-family: 'Courier New', monospace;
  178.             font-size: 0.9em;
  179.             color: #00ff00;
  180.             border-radius: 5px;
  181.             line-height: 1.6;
  182.         }
  183.  
  184.         .terminal-line {
  185.             margin: 2px 0;
  186.             padding: 2px 5px;
  187.             transition: background 0.3s;
  188.         }
  189.  
  190.         .terminal-line:hover {
  191.             background: rgba(255, 150, 0, 0.1);
  192.         }
  193.  
  194.         .terminal-prime {
  195.             color: #ffaa00;
  196.             font-weight: bold;
  197.         }
  198.  
  199.         .terminal-info {
  200.             color: #888;
  201.             font-style: italic;
  202.         }
  203.  
  204.         .terminal-stats {
  205.             padding: 10px;
  206.             border-top: 1px solid rgba(255, 100, 0, 0.3);
  207.             color: #ffaa00;
  208.             font-size: 0.85em;
  209.         }
  210.  
  211.         .prime-display {
  212.             background: rgba(0, 0, 0, 0.7);
  213.             padding: 15px;
  214.             border-radius: 10px;
  215.             border: 1px solid rgba(255, 100, 0, 0.5);
  216.         }
  217.  
  218.         .current-prime {
  219.             font-size: 1.8em;
  220.             text-align: center;
  221.             margin-bottom: 10px;
  222.             color: #ffffff;
  223.             text-shadow: 0 0 20px rgba(255, 150, 0, 0.7);
  224.         }
  225.  
  226.         .prime-count {
  227.             text-align: center;
  228.             font-size: 1.1em;
  229.             color: #ffaa00;
  230.         }
  231.  
  232.         .algorithm-info {
  233.             background: rgba(50, 20, 0, 0.3);
  234.             padding: 12px;
  235.             border-radius: 8px;
  236.             border: 1px solid rgba(255, 150, 0, 0.3);
  237.         }
  238.  
  239.         .algorithm-name {
  240.             font-size: 1em;
  241.             color: #ffff00;
  242.             margin-bottom: 5px;
  243.         }
  244.  
  245.         .algorithm-equation {
  246.             font-family: 'Courier New', monospace;
  247.             color: #00ffff;
  248.             font-size: 0.85em;
  249.             word-break: break-all;
  250.             padding: 8px;
  251.             background: rgba(0, 0, 0, 0.5);
  252.             border-radius: 5px;
  253.             margin-top: 8px;
  254.         }
  255.  
  256.         .loading-container {
  257.             margin: 15px 0;
  258.         }
  259.  
  260.         .loading-bar-bg {
  261.             width: 100%;
  262.             height: 35px;
  263.             background: rgba(0, 0, 0, 0.5);
  264.             border-radius: 20px;
  265.             overflow: hidden;
  266.             position: relative;
  267.             border: 2px solid rgba(255, 100, 0, 0.3);
  268.         }
  269.  
  270.         .loading-bar {
  271.             height: 100%;
  272.             width: 0%;
  273.             background: linear-gradient(90deg,
  274.                 #ff6600 0%,
  275.                 #ffaa00 50%,
  276.                 #ff3300 100%);
  277.             border-radius: 18px;
  278.             transition: width 0.1s linear;
  279.             position: relative;
  280.             overflow: hidden;
  281.         }
  282.  
  283.         .loading-bar::after {
  284.             content: '';
  285.             position: absolute;
  286.             top: 0;
  287.             left: 0;
  288.             right: 0;
  289.             bottom: 0;
  290.             background: linear-gradient(90deg,
  291.                 transparent,
  292.                 rgba(255, 255, 255, 0.4),
  293.                 transparent);
  294.             animation: shimmer 1.5s infinite;
  295.         }
  296.  
  297.         @keyframes shimmer {
  298.             0% { transform: translateX(-100%); }
  299.             100% { transform: translateX(100%); }
  300.         }
  301.  
  302.         .loading-label {
  303.             text-align: center;
  304.             margin-top: 8px;
  305.             font-size: 0.85em;
  306.         }
  307.  
  308.         .phase-indicator {
  309.             display: inline-block;
  310.             padding: 2px 8px;
  311.             border-radius: 5px;
  312.             margin-left: 10px;
  313.             font-size: 0.8em;
  314.         }
  315.  
  316.         .phase-calculating {
  317.             background: rgba(255, 150, 0, 0.2);
  318.             color: #ffaa00;
  319.         }
  320.  
  321.         .phase-checking {
  322.             background: rgba(255, 50, 0, 0.2);
  323.             color: #ff6600;
  324.         }
  325.  
  326.         .controls {
  327.             display: flex;
  328.             justify-content: center;
  329.             gap: 15px;
  330.             flex-wrap: wrap;
  331.         }
  332.  
  333.         button {
  334.             padding: 10px 25px;
  335.             font-size: 1em;
  336.             background: linear-gradient(135deg, #ff6600, #ffaa00);
  337.             color: #000;
  338.             border: none;
  339.             border-radius: 25px;
  340.             cursor: pointer;
  341.             font-weight: bold;
  342.             transition: all 0.3s ease;
  343.             box-shadow: 0 0 20px rgba(255, 100, 0, 0.3);
  344.         }
  345.  
  346.         button:hover {
  347.             transform: translateY(-2px);
  348.             box-shadow: 0 5px 30px rgba(255, 100, 0, 0.5);
  349.         }
  350.  
  351.         button:active {
  352.             transform: translateY(0);
  353.         }
  354.  
  355.         button.paused {
  356.             background: linear-gradient(135deg, #ff0088, #ff00ff);
  357.             box-shadow: 0 0 20px rgba(255, 0, 136, 0.3);
  358.         }
  359.  
  360.         .stats {
  361.             display: grid;
  362.             grid-template-columns: repeat(3, 1fr);
  363.             gap: 10px;
  364.         }
  365.  
  366.         .stat-card {
  367.             background: rgba(0, 0, 0, 0.5);
  368.             padding: 10px;
  369.             border-radius: 8px;
  370.             border: 1px solid rgba(255, 100, 0, 0.2);
  371.         }
  372.  
  373.         .stat-label {
  374.             color: #888;
  375.             font-size: 0.75em;
  376.             margin-bottom: 3px;
  377.         }
  378.  
  379.         .stat-value {
  380.             color: #ffaa00;
  381.             font-size: 1em;
  382.             font-weight: bold;
  383.         }
  384.  
  385.         .info-text {
  386.             text-align: center;
  387.             margin-top: 10px;
  388.             color: #888;
  389.             font-size: 0.8em;
  390.         }
  391.  
  392.         ::-webkit-scrollbar {
  393.             width: 8px;
  394.         }
  395.  
  396.         ::-webkit-scrollbar-track {
  397.             background: rgba(0, 0, 0, 0.3);
  398.             border-radius: 4px;
  399.         }
  400.  
  401.         ::-webkit-scrollbar-thumb {
  402.             background: rgba(255, 100, 0, 0.5);
  403.             border-radius: 4px;
  404.         }
  405.  
  406.         ::-webkit-scrollbar-thumb:hover {
  407.             background: rgba(255, 150, 0, 0.7);
  408.         }
  409.  
  410.         input[type="file"] {
  411.             display: none;
  412.         }
  413.  
  414.         @media (max-width: 1024px) {
  415.             .container {
  416.                 grid-template-columns: 1fr;
  417.                 max-width: 95%;
  418.             }
  419.            
  420.             .terminal-container {
  421.                 height: 300px;
  422.             }
  423.         }
  424.     </style>
  425. </head>
  426. <body>
  427.     <div class="phoenix-particles" id="phoenixParticles"></div>
  428.    
  429.     <div class="container">
  430.         <div class="main-panel">
  431.             <h1>🔥 The Prime Decider - Phoenix Edition 🔥</h1>
  432.            
  433.             <div class="prime-display">
  434.                 <div class="current-prime" id="currentPrime">7</div>
  435.                 <div class="prime-count">Prime #<span id="primeCount">4</span></div>
  436.             </div>
  437.  
  438.             <div class="algorithm-info">
  439.                 <div class="algorithm-name">Current Algorithm: <span id="algorithmName">Trial Division</span></div>
  440.                 <div class="algorithm-equation" id="algorithmEquation">n % d !== 0 for all d ≤ √n</div>
  441.             </div>
  442.  
  443.             <div class="loading-container">
  444.                 <div class="loading-bar-bg">
  445.                     <div class="loading-bar" id="loadingBar"></div>
  446.                 </div>
  447.                 <div class="loading-label">
  448.                     <span id="loadingPhase">Calculating</span>
  449.                     <span class="phase-indicator phase-calculating" id="phaseIndicator">Computing</span>
  450.                 </div>
  451.             </div>
  452.  
  453.             <div class="controls">
  454.                 <button id="pauseBtn" onclick="togglePause()">Pause</button>
  455.                 <button onclick="saveProgress()">🔥 Save Phoenix</button>
  456.                 <button onclick="document.getElementById('fileInput').click()">🔥 Load Phoenix</button>
  457.                 <button onclick="clearTerminal()">Clear Terminal</button>
  458.                 <input type="file" id="fileInput" accept=".txt" onchange="loadProgress(event)">
  459.             </div>
  460.  
  461.             <div class="stats">
  462.                 <div class="stat-card">
  463.                     <div class="stat-label">Started From</div>
  464.                     <div class="stat-value" id="startedFrom">7</div>
  465.                 </div>
  466.                 <div class="stat-card">
  467.                     <div class="stat-label">Current Number</div>
  468.                     <div class="stat-value" id="currentNumber">7</div>
  469.                 </div>
  470.                 <div class="stat-card">
  471.                     <div class="stat-label">Primes Found</div>
  472.                     <div class="stat-value" id="totalPrimes">4</div>
  473.                 </div>
  474.                 <div class="stat-card">
  475.                     <div class="stat-label">Numbers Checked</div>
  476.                     <div class="stat-value" id="numbersChecked">7</div>
  477.                 </div>
  478.                 <div class="stat-card">
  479.                     <div class="stat-label">Algorithm Cycles</div>
  480.                     <div class="stat-value" id="algorithmCycles">0</div>
  481.                 </div>
  482.                 <div class="stat-card">
  483.                     <div class="stat-label">Runtime</div>
  484.                     <div class="stat-value" id="runtime">00:00:00</div>
  485.                 </div>
  486.             </div>
  487.  
  488.             <div class="info-text">
  489.                 Press 'P' to pause/resume • Save/Load your eternal Prime hunt • Phoenix rises from the ashes!
  490.             </div>
  491.         </div>
  492.  
  493.         <div class="terminal-container">
  494.             <div class="terminal-header">
  495.                 <div class="terminal-title">🔥 Phoenix Terminal Output</div>
  496.                 <div class="terminal-controls">
  497.                     <button class="terminal-btn" onclick="exportTerminal()">Export</button>
  498.                     <button class="terminal-btn" onclick="scrollToBottom()">Bottom</button>
  499.                 </div>
  500.             </div>
  501.             <div class="terminal-output" id="terminalOutput">
  502.                 <div class="terminal-line terminal-info">// Phoenix Prime Decider initialized...</div>
  503.                 <div class="terminal-line terminal-info">// Starting from sacred number 7...</div>
  504.                 <div class="terminal-line terminal-info">// Initial primes loaded: 2, 3, 5, 7</div>
  505.             </div>
  506.             <div class="terminal-stats" id="terminalStats">
  507.                 Total Terminal Entries: <span id="terminalCount">3</span>
  508.             </div>
  509.         </div>
  510.     </div>
  511.  
  512.     <script>
  513.         // Phoenix particles
  514.         function createPhoenixParticles() {
  515.             const container = document.getElementById('phoenixParticles');
  516.             for (let i = 0; i < 30; i++) {
  517.                const particle = document.createElement('div');
  518.                particle.className = 'phoenix-particle';
  519.                particle.style.left = Math.random() * 100 + '%';
  520.                particle.style.animationDelay = Math.random() * 4 + 's';
  521.                particle.style.animationDuration = (3 + Math.random() * 3) + 's';
  522.                container.appendChild(particle);
  523.            }
  524.        }
  525.  
  526.        // Prime calculation state
  527.        let isPaused = false;
  528.        let currentNum = 7;
  529.        let primeCount = 4;
  530.        let totalChecked = 7;
  531.        let algorithmCycles = 0;
  532.        let startTime = Date.now();
  533.        let knownPrimes = [2, 3, 5, 7];
  534.        let currentAlgorithm = 0;
  535.        let progress = 0;
  536.        let isChecking = false;
  537.        let terminalLines = [];
  538.        let sessionStartTime = new Date().toISOString();
  539.  
  540.        // Algorithm definitions
  541.        const algorithms = [
  542.            {
  543.                name: "Trial Division",
  544.                equation: "n % d !== 0 for all d ≤ √n",
  545.                check: trialDivision
  546.            },
  547.            {
  548.                name: "6k ± 1 Optimization",
  549.                equation: "Check n = 6k ± 1, then n % p !== 0 for primes p ≤ √n",
  550.                check: sixKOptimization
  551.            },
  552.            {
  553.                name: "Miller-Rabin Probabilistic",
  554.                equation: "n-1 = 2^r × d, check a^d ≡ 1 (mod n) or a^(2^i×d) ≡ -1 (mod n)",
  555.                check: millerRabin
  556.            },
  557.            {
  558.                name: "Fermat's Little Theorem",
  559.                equation: "a^(n-1) ≡ 1 (mod n) for coprime a",
  560.                check: fermatTest
  561.            },
  562.            {
  563.                name: "Solovay-Strassen",
  564.                equation: "a^((n-1)/2) ≡ (a/n) (mod n) where (a/n) is Jacobi symbol",
  565.                check: solovayStrassen
  566.            },
  567.            {
  568.                name: "Wheel Factorization",
  569.                equation: "Skip multiples of 2,3,5: check n = 30k + r where r ∈ {1,7,11,13,17,19,23,29}",
  570.                check: wheelFactorization
  571.            },
  572.            {
  573.                name: "Sieve-based Check",
  574.                equation: "Use cached primes: n % p !== 0 for all cached primes p ≤ √n",
  575.                check: sieveBasedCheck
  576.            }
  577.        ];
  578.  
  579.        // Algorithm implementations
  580.        function trialDivision(n) {
  581.            if (n <= 1) return false;
  582.            if (n <= 3) return true;
  583.            if (n % 2 === 0 || n % 3 === 0) return false;
  584.            
  585.            for (let i = 5; i * i <= n; i += 6) {
  586.                if (n % i === 0 || n % (i + 2) === 0) return false;
  587.            }
  588.            return true;
  589.        }
  590.  
  591.        function sixKOptimization(n) {
  592.            if (n <= 1) return false;
  593.            if (n <= 3) return true;
  594.            if (n % 2 === 0 || n % 3 === 0) return false;
  595.            
  596.            let limit = Math.sqrt(n);
  597.            for (let i = 5; i <= limit; i += 6) {
  598.                if (n % i === 0 || n % (i + 2) === 0) return false;
  599.            }
  600.            return true;
  601.        }
  602.  
  603.        function modPow(base, exp, mod) {
  604.            let result = 1n;
  605.            base = BigInt(base) % BigInt(mod);
  606.            exp = BigInt(exp);
  607.            mod = BigInt(mod);
  608.            
  609.            while (exp > 0n) {
  610.                 if (exp % 2n === 1n) {
  611.                     result = (result * base) % mod;
  612.                 }
  613.                 exp = exp >> 1n;
  614.                 base = (base * base) % mod;
  615.             }
  616.             return Number(result);
  617.         }
  618.  
  619.         function millerRabin(n, k = 5) {
  620.             if (n <= 1) return false;
  621.            if (n === 2 || n === 3) return true;
  622.            if (n % 2 === 0) return false;
  623.            
  624.            let r = 0;
  625.            let d = n - 1;
  626.            while (d % 2 === 0) {
  627.                d /= 2;
  628.                r++;
  629.            }
  630.            
  631.            for (let i = 0; i < k; i++) {
  632.                let a = 2 + Math.floor(Math.random() * (n - 4));
  633.                let x = modPow(a, d, n);
  634.                
  635.                if (x === 1 || x === n - 1) continue;
  636.                
  637.                let continueWitness = false;
  638.                for (let j = 0; j < r - 1; j++) {
  639.                    x = modPow(x, 2, n);
  640.                    if (x === n - 1) {
  641.                        continueWitness = true;
  642.                        break;
  643.                    }
  644.                }
  645.                
  646.                if (!continueWitness) return false;
  647.            }
  648.            return true;
  649.        }
  650.  
  651.        function fermatTest(n, k = 5) {
  652.            if (n <= 1) return false;
  653.            if (n <= 3) return true;
  654.            if (n % 2 === 0) return false;
  655.            
  656.            for (let i = 0; i < k; i++) {
  657.                let a = 2 + Math.floor(Math.random() * (n - 4));
  658.                if (modPow(a, n - 1, n) !== 1) return false;
  659.            }
  660.            return true;
  661.        }
  662.  
  663.        function jacobiSymbol(a, n) {
  664.            if (n <= 0 || n % 2 === 0) return 0;
  665.            a = a % n;
  666.            let result = 1;
  667.            
  668.            while (a !== 0) {
  669.                while (a % 2 === 0) {
  670.                    a /= 2;
  671.                    let r = n % 8;
  672.                    if (r === 3 || r === 5) result = -result;
  673.                }
  674.                [a, n] = [n, a];
  675.                if (a % 4 === 3 && n % 4 === 3) result = -result;
  676.                a = a % n;
  677.            }
  678.            
  679.            return n === 1 ? result : 0;
  680.        }
  681.  
  682.        function solovayStrassen(n, k = 5) {
  683.            if (n <= 1) return false;
  684.            if (n === 2 || n === 3) return true;
  685.            if (n % 2 === 0) return false;
  686.            
  687.            for (let i = 0; i < k; i++) {
  688.                let a = 2 + Math.floor(Math.random() * (n - 3));
  689.                let jacobi = jacobiSymbol(a, n) % n;
  690.                if (jacobi < 0) jacobi += n;
  691.                
  692.                if (jacobi === 0 || modPow(a, (n - 1) / 2, n) !== jacobi) {
  693.                    return false;
  694.                }
  695.            }
  696.            return true;
  697.        }
  698.  
  699.        function wheelFactorization(n) {
  700.            if (n <= 1) return false;
  701.            if (n === 2 || n === 3 || n === 5) return true;
  702.            if (n % 2 === 0 || n % 3 === 0 || n % 5 === 0) return false;
  703.            
  704.            const wheel = [1, 7, 11, 13, 17, 19, 23, 29];
  705.            let w = 30;
  706.            let limit = Math.sqrt(n);
  707.            
  708.            for (let k = 0; k * w <= limit; k++) {
  709.                for (let r of wheel) {
  710.                    let d = k * w + r;
  711.                    if (d > 1 && d <= limit && n % d === 0) return false;
  712.                 }
  713.             }
  714.             return true;
  715.         }
  716.  
  717.         function sieveBasedCheck(n) {
  718.             if (n <= 1) return false;
  719.            
  720.            for (let prime of knownPrimes) {
  721.                if (prime * prime > n) break;
  722.                 if (n % prime === 0) return n === prime;
  723.             }
  724.             return true;
  725.         }
  726.  
  727.         // Error checking using different algorithm
  728.         function errorCheck(n, primaryResult) {
  729.             let verifyAlg = (currentAlgorithm + 3) % algorithms.length;
  730.             return algorithms[verifyAlg].check(n) === primaryResult;
  731.         }
  732.  
  733.         // Terminal functions
  734.         function addToTerminal(message, type = 'info') {
  735.             const terminal = document.getElementById('terminalOutput');
  736.             const timestamp = new Date().toISOString();
  737.             const line = document.createElement('div');
  738.             line.className = `terminal-line terminal-${type}`;
  739.            
  740.             if (type === 'prime') {
  741.                 line.innerHTML = `<span style="color: #666;">[${timestamp}]</span> <span class="terminal-prime">PRIME FOUND: ${message}</span>`;
  742.                 terminalLines.push({
  743.                     timestamp: timestamp,
  744.                     prime: parseInt(message),
  745.                     index: primeCount
  746.                 });
  747.             } else {
  748.                 line.innerHTML = `<span style="color: #666;">[${timestamp}]</span> ${message}`;
  749.             }
  750.            
  751.             terminal.appendChild(line);
  752.             updateTerminalStats();
  753.            
  754.             // Auto-scroll to bottom
  755.             terminal.scrollTop = terminal.scrollHeight;
  756.         }
  757.  
  758.         function updateTerminalStats() {
  759.             const count = document.getElementById('terminalOutput').children.length;
  760.             document.getElementById('terminalCount').textContent = count;
  761.         }
  762.  
  763.         function clearTerminal() {
  764.             const terminal = document.getElementById('terminalOutput');
  765.             terminal.innerHTML = '<div class="terminal-line terminal-info">// Terminal cleared - Phoenix rises anew...</div>';
  766.             updateTerminalStats();
  767.         }
  768.  
  769.         function scrollToBottom() {
  770.             const terminal = document.getElementById('terminalOutput');
  771.             terminal.scrollTop = terminal.scrollHeight;
  772.         }
  773.  
  774.         function exportTerminal() {
  775.             let content = `PHOENIX PRIME DECIDER - TERMINAL EXPORT\n`;
  776.             content += `Session Started: ${sessionStartTime}\n`;
  777.             content += `Export Time: ${new Date().toISOString()}\n`;
  778.             content += `Total Primes Found: ${primeCount}\n`;
  779.             content += `========================================\n\n`;
  780.            
  781.             // Export in tab-delimited format
  782.             content += `INDEX\tPRIME\tTIMESTAMP\n`;
  783.             terminalLines.forEach(line => {
  784.                 content += `${line.index}\t${line.prime}\t${line.timestamp}\n`;
  785.             });
  786.            
  787.             const blob = new Blob([content], { type: 'text/plain' });
  788.             const url = window.URL.createObjectURL(blob);
  789.             const a = document.createElement('a');
  790.             a.href = url;
  791.             a.download = `phoenix_primes_${Date.now()}.txt`;
  792.             a.click();
  793.             window.URL.revokeObjectURL(url);
  794.            
  795.             addToTerminal('// Terminal exported to file', 'info');
  796.         }
  797.  
  798.         // Save/Load functions
  799.         function saveProgress() {
  800.             const saveData = {
  801.                 version: "1.0",
  802.                 timestamp: new Date().toISOString(),
  803.                 currentNum: currentNum,
  804.                 primeCount: primeCount,
  805.                 totalChecked: totalChecked,
  806.                 algorithmCycles: algorithmCycles,
  807.                 knownPrimes: knownPrimes,
  808.                 terminalLines: terminalLines,
  809.                 sessionStartTime: sessionStartTime
  810.             };
  811.            
  812.             let content = `PHOENIX PRIME DECIDER - SAVE FILE v1.0\n`;
  813.             content += `Saved: ${saveData.timestamp}\n`;
  814.             content += `Current: ${currentNum}\n`;
  815.             content += `Count: ${primeCount}\n`;
  816.             content += `Checked: ${totalChecked}\n`;
  817.             content += `Cycles: ${algorithmCycles}\n`;
  818.             content += `Session: ${sessionStartTime}\n`;
  819.             content += `========================================\n`;
  820.             content += `INDEX\tPRIME\tTIMESTAMP\n`;
  821.            
  822.             terminalLines.forEach(line => {
  823.                 content += `${line.index}\t${line.prime}\t${line.timestamp}\n`;
  824.             });
  825.            
  826.             const blob = new Blob([content], { type: 'text/plain' });
  827.             const url = window.URL.createObjectURL(blob);
  828.             const a = document.createElement('a');
  829.             a.href = url;
  830.             a.download = `phoenix_save_${Date.now()}.txt`;
  831.             a.click();
  832.             window.URL.revokeObjectURL(url);
  833.            
  834.             addToTerminal(`// Phoenix state saved! Primes: ${primeCount}, Current: ${currentNum}`, 'info');
  835.         }
  836.  
  837.         function loadProgress(event) {
  838.             const file = event.target.files[0];
  839.             if (!file) return;
  840.            
  841.             const reader = new FileReader();
  842.             reader.onload = function(e) {
  843.                 try {
  844.                     const content = e.target.result;
  845.                     const lines = content.split('\n');
  846.                    
  847.                     // Parse header information
  848.                     let loadedData = {
  849.                         currentNum: 7,
  850.                         primeCount: 0,
  851.                         totalChecked: 7,
  852.                         algorithmCycles: 0,
  853.                         primes: []
  854.                     };
  855.                    
  856.                     // Parse metadata from header
  857.                     lines.forEach((line, index) => {
  858.                         if (line.startsWith('Current:')) {
  859.                             loadedData.currentNum = parseInt(line.split(':')[1].trim());
  860.                         } else if (line.startsWith('Count:')) {
  861.                             loadedData.primeCount = parseInt(line.split(':')[1].trim());
  862.                         } else if (line.startsWith('Checked:')) {
  863.                             loadedData.totalChecked = parseInt(line.split(':')[1].trim());
  864.                         } else if (line.startsWith('Cycles:')) {
  865.                             loadedData.algorithmCycles = parseInt(line.split(':')[1].trim());
  866.                         }
  867.                     });
  868.                    
  869.                     // Find the data section (after the separator)
  870.                     let dataStartIndex = lines.findIndex(line => line.includes('INDEX\tPRIME\tTIMESTAMP'));
  871.                    
  872.                     if (dataStartIndex !== -1) {
  873.                         // Clear terminal and add loaded primes
  874.                         clearTerminal();
  875.                         addToTerminal('// Phoenix rises from the ashes! Loading saved state...', 'info');
  876.                        
  877.                         terminalLines = [];
  878.                         knownPrimes = [2, 3, 5, 7]; // Reset to initial primes
  879.                        
  880.                         // Parse and load all primes
  881.                         for (let i = dataStartIndex + 1; i < lines.length; i++) {
  882.                            const line = lines[i].trim();
  883.                            if (line && !line.startsWith('//')) {
  884.                                const parts = line.split('\t');
  885.                                if (parts.length >= 2) {
  886.                                     const index = parseInt(parts[0]);
  887.                                     const prime = parseInt(parts[1]);
  888.                                     const timestamp = parts[2] || new Date().toISOString();
  889.                                    
  890.                                     if (!isNaN(prime) && prime > 7) {
  891.                                        knownPrimes.push(prime);
  892.                                         terminalLines.push({
  893.                                             timestamp: timestamp,
  894.                                             prime: prime,
  895.                                             index: index
  896.                                         });
  897.                                        
  898.                                         // Add to terminal display
  899.                                         const terminalLine = document.createElement('div');
  900.                                         terminalLine.className = 'terminal-line terminal-prime';
  901.                                         terminalLine.innerHTML = `<span style="color: #666;">[${timestamp}]</span> <span class="terminal-prime">PRIME FOUND: ${prime}</span>`;
  902.                                         document.getElementById('terminalOutput').appendChild(terminalLine);
  903.                                     }
  904.                                 }
  905.                             }
  906.                         }
  907.                        
  908.                         // Update state from loaded data
  909.                         currentNum = loadedData.currentNum || knownPrimes[knownPrimes.length - 1];
  910.                         primeCount = loadedData.primeCount || knownPrimes.length;
  911.                         totalChecked = loadedData.totalChecked || currentNum;
  912.                         algorithmCycles = loadedData.algorithmCycles || 0;
  913.                        
  914.                         // Update display
  915.                         updateDisplay();
  916.                         updateTerminalStats();
  917.                        
  918.                         addToTerminal(`// Phoenix restored! Loaded ${primeCount} primes, continuing from ${currentNum}`, 'info');
  919.                         addToTerminal(`// Last prime discovered: ${knownPrimes[knownPrimes.length - 1]}`, 'info');
  920.                        
  921.                         // Update starting point display
  922.                         document.getElementById('startedFrom').textContent = currentNum.toLocaleString();
  923.                        
  924.                         // Resume if not paused
  925.                         if (!isPaused) {
  926.                             setTimeout(calculateNextPrime, 1000);
  927.                         }
  928.                     } else {
  929.                         addToTerminal('// Error: Invalid save file format', 'info');
  930.                     }
  931.                 } catch (error) {
  932.                     console.error('Load error:', error);
  933.                     addToTerminal('// Error loading save file: ' + error.message, 'info');
  934.                 }
  935.             };
  936.            
  937.             reader.readAsText(file);
  938.             event.target.value = ''; // Reset file input
  939.         }
  940.  
  941.         // Update display
  942.         function updateDisplay() {
  943.             document.getElementById('currentPrime').textContent = knownPrimes[knownPrimes.length - 1].toLocaleString();
  944.             document.getElementById('primeCount').textContent = primeCount.toLocaleString();
  945.             document.getElementById('currentNumber').textContent = currentNum.toLocaleString();
  946.             document.getElementById('totalPrimes').textContent = primeCount.toLocaleString();
  947.             document.getElementById('numbersChecked').textContent = totalChecked.toLocaleString();
  948.             document.getElementById('algorithmCycles').textContent = algorithmCycles.toLocaleString();
  949.         }
  950.  
  951.         // Update runtime
  952.         function updateRuntime() {
  953.             let elapsed = Date.now() - startTime;
  954.             let hours = Math.floor(elapsed / 3600000);
  955.             let minutes = Math.floor((elapsed % 3600000) / 60000);
  956.             let seconds = Math.floor((elapsed % 60000) / 1000);
  957.            
  958.             document.getElementById('runtime').textContent =
  959.                 `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  960.         }
  961.  
  962.         // Main calculation loop
  963.         async function calculateNextPrime() {
  964.             if (isPaused) return;
  965.            
  966.             currentNum++;
  967.             totalChecked++;
  968.            
  969.             // Special check for 21
  970.             if (currentNum === 21) {
  971.                 addToTerminal(`// Checking sacred number 21... (3 × 7 = not prime)`, 'info');
  972.             }
  973.            
  974.             // Select algorithm (rotate every 100 numbers)
  975.             if (totalChecked % 100 === 0) {
  976.                 currentAlgorithm = (currentAlgorithm + 1) % algorithms.length;
  977.                 algorithmCycles++;
  978.                 document.getElementById('algorithmName').textContent = algorithms[currentAlgorithm].name;
  979.                 document.getElementById('algorithmEquation').textContent = algorithms[currentAlgorithm].equation;
  980.                 addToTerminal(`// Algorithm switched to: ${algorithms[currentAlgorithm].name}`, 'info');
  981.             }
  982.            
  983.             // Simulate calculation phase (0-50%)
  984.             for (let i = 0; i <= 50; i += 2) {
  985.                if (isPaused) return;
  986.                progress = i;
  987.                document.getElementById('loadingBar').style.width = progress + '%';
  988.                document.getElementById('loadingPhase').textContent = 'Calculating';
  989.                document.getElementById('phaseIndicator').textContent = 'Computing';
  990.                document.getElementById('phaseIndicator').className = 'phase-indicator phase-calculating';
  991.                await new Promise(resolve => setTimeout(resolve, 10));
  992.             }
  993.            
  994.             // Perform actual prime check
  995.             let isPrime = algorithms[currentAlgorithm].check(currentNum);
  996.            
  997.             // Error checking phase (50-100%)
  998.             isChecking = true;
  999.             for (let i = 50; i <= 100; i += 2) {
  1000.                if (isPaused) return;
  1001.                progress = i;
  1002.                document.getElementById('loadingBar').style.width = progress + '%';
  1003.                document.getElementById('loadingPhase').textContent = 'Error Checking';
  1004.                document.getElementById('phaseIndicator').textContent = 'Verifying';
  1005.                document.getElementById('phaseIndicator').className = 'phase-indicator phase-checking';
  1006.                await new Promise(resolve => setTimeout(resolve, 10));
  1007.             }
  1008.            
  1009.             // Verify with error checking
  1010.             let isVerified = errorCheck(currentNum, isPrime);
  1011.            
  1012.             if (isPrime && isVerified) {
  1013.                primeCount++;
  1014.                 knownPrimes.push(currentNum);
  1015.                
  1016.                 // Add to terminal
  1017.                 addToTerminal(currentNum.toLocaleString(), 'prime');
  1018.                
  1019.                 // Keep only last 1000 primes in memory for performance
  1020.                 if (knownPrimes.length > 1000) {
  1021.                     knownPrimes = knownPrimes.slice(-1000);
  1022.                 }
  1023.                
  1024.                 updateDisplay();
  1025.             }
  1026.            
  1027.             // Reset progress bar
  1028.             progress = 0;
  1029.             document.getElementById('loadingBar').style.width = '0%';
  1030.             isChecking = false;
  1031.            
  1032.             // Continue to next number
  1033.             setTimeout(calculateNextPrime, 1);
  1034.         }
  1035.  
  1036.         // Pause/Resume functionality
  1037.         function togglePause() {
  1038.             isPaused = !isPaused;
  1039.             const btn = document.getElementById('pauseBtn');
  1040.             btn.textContent = isPaused ? 'Resume' : 'Pause';
  1041.             btn.className = isPaused ? 'paused' : '';
  1042.            
  1043.             if (!isPaused) {
  1044.                 addToTerminal('// Phoenix awakens! Resuming prime hunt...', 'info');
  1045.                 calculateNextPrime();
  1046.             } else {
  1047.                 addToTerminal('// Phoenix rests... Prime hunt paused', 'info');
  1048.             }
  1049.         }
  1050.  
  1051.         // Keyboard controls
  1052.         document.addEventListener('keydown', (e) => {
  1053.             if (e.key.toLowerCase() === 'p') {
  1054.                 togglePause();
  1055.             }
  1056.         });
  1057.  
  1058.         // Initialize special starting points
  1059.         function initializeWithSpecialPrimes() {
  1060.             // Ensure we include 21 in our checks even though it's not prime
  1061.             if (!knownPrimes.includes(21)) {
  1062.                 currentNum = 20; // Start just before 21 to ensure it's checked
  1063.             }
  1064.         }
  1065.  
  1066.         // Start the application
  1067.         window.onload = () => {
  1068.             createPhoenixParticles();
  1069.             initializeWithSpecialPrimes();
  1070.             updateDisplay();
  1071.             setInterval(updateRuntime, 1000);
  1072.             addToTerminal('// Phoenix Prime Decider fully initialized!', 'info');
  1073.             addToTerminal('// Press "P" or click Pause to control the hunt', 'info');
  1074.             addToTerminal('// Save your progress to resurrect later!', 'info');
  1075.             calculateNextPrime();
  1076.         };
  1077.     </script>
  1078. </body>
  1079. </html>
  1080.  
Advertisement
Add Comment
Please, Sign In to add comment