XTaylorSpenceX

Phoenix Prime Calculator v1.0GG

Sep 18th, 2025
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 22.52 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.         /* CSS Reset and Global Styles */
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.             box-sizing: border-box;
  13.         }
  14.  
  15.         body {
  16.             font-family: 'Courier New', monospace;
  17.             background: linear-gradient(135deg, #0a0a0a 0%, #1a0033 50%, #330066 100%);
  18.             color: #00ff88;
  19.             min-height: 100vh;
  20.             display: flex;
  21.             justify-content: center;
  22.             align-items: center;
  23.             overflow: hidden;
  24.             position: relative;
  25.         }
  26.  
  27.         /* Phoenix Background Effects */
  28.         body::before {
  29.             content: '';
  30.             position: absolute;
  31.             width: 200%;
  32.             height: 200%;
  33.             background:
  34.                 radial-gradient(circle at 20% 80%, rgba(255, 100, 0, 0.15) 0%, transparent 50%),
  35.                 radial-gradient(circle at 80% 20%, rgba(255, 200, 0, 0.15) 0%, transparent 50%),
  36.                 radial-gradient(circle at 40% 40%, rgba(255, 50, 0, 0.1) 0%, transparent 50%);
  37.             animation: phoenixFloat 25s ease-in-out infinite;
  38.         }
  39.  
  40.         @keyframes phoenixFloat {
  41.             0%, 100% { transform: translate(0, 0) rotate(0deg) scale(1); }
  42.             25% { transform: translate(-30px, -30px) rotate(90deg) scale(1.1); }
  43.             50% { transform: translate(30px, -50px) rotate(180deg) scale(0.95); }
  44.             75% { transform: translate(-20px, 20px) rotate(270deg) scale(1.05); }
  45.         }
  46.  
  47.         .phoenix-particles {
  48.             position: absolute;
  49.             top: 0; left: 0;
  50.             width: 100%;
  51.             height: 100%;
  52.             overflow: hidden;
  53.             pointer-events: none;
  54.         }
  55.  
  56.         .phoenix-particle {
  57.             position: absolute;
  58.             width: 4px;
  59.             height: 4px;
  60.             background: radial-gradient(circle, rgba(255, 150, 0, 0.8), transparent);
  61.             border-radius: 50%;
  62.             animation: rise 4s linear infinite;
  63.         }
  64.  
  65.         @keyframes rise {
  66.             0% { transform: translateY(100vh) scale(0); opacity: 0; }
  67.             10% { opacity: 1; }
  68.             90% { opacity: 1; }
  69.             100% { transform: translateY(-100vh) scale(1.5); opacity: 0; }
  70.         }
  71.  
  72.         /* Main App Container */
  73.         .container {
  74.             background: rgba(10, 10, 30, 0.95);
  75.             border-radius: 20px;
  76.             padding: 30px;
  77.             box-shadow:
  78.                 0 0 100px rgba(255, 100, 0, 0.3),
  79.                 inset 0 0 50px rgba(255, 150, 0, 0.1);
  80.             border: 2px solid rgba(255, 100, 0, 0.4);
  81.             max-width: 1200px;
  82.             width: 95%;
  83.             position: relative;
  84.             z-index: 10;
  85.             display: grid;
  86.             grid-template-columns: 1fr 450px;
  87.             gap: 30px;
  88.             max-height: 95vh;
  89.         }
  90.  
  91.         .main-panel, .terminal-container {
  92.             display: flex;
  93.             flex-direction: column;
  94.             gap: 15px;
  95.             overflow: hidden;
  96.         }
  97.  
  98.         h1 {
  99.             text-align: center;
  100.             font-size: 2.2em;
  101.             text-shadow:
  102.                 0 0 20px #ff6600, 0 0 40px #ff3300, 0 0 60px #ff0000;
  103.             animation: phoenixPulse 3s ease-in-out infinite;
  104.             background: linear-gradient(45deg, #ff6600, #ffaa00, #ff3300);
  105.             -webkit-background-clip: text;
  106.             -webkit-text-fill-color: transparent;
  107.             background-clip: text;
  108.             margin-bottom: 10px;
  109.         }
  110.  
  111.         @keyframes phoenixPulse {
  112.             0%, 100% { filter: brightness(1); transform: scale(1); }
  113.             50% { filter: brightness(1.3); transform: scale(1.02); }
  114.         }
  115.        
  116.         /* Terminal Window Styles */
  117.         .terminal-container {
  118.             background: #000000;
  119.             border: 2px solid rgba(255, 100, 0, 0.5);
  120.             border-radius: 10px;
  121.             padding: 15px;
  122.             box-shadow: inset 0 0 20px rgba(255, 100, 0, 0.2);
  123.             height: calc(95vh - 60px);
  124.         }
  125.  
  126.         .terminal-header {
  127.             display: flex;
  128.             justify-content: space-between;
  129.             align-items: center;
  130.             padding-bottom: 10px;
  131.             border-bottom: 1px solid rgba(255, 100, 0, 0.3);
  132.             flex-shrink: 0;
  133.         }
  134.  
  135.         .terminal-title {
  136.             color: #ffaa00;
  137.             font-size: 1.1em;
  138.             text-shadow: 0 0 10px rgba(255, 150, 0, 0.5);
  139.         }
  140.  
  141.         .terminal-output {
  142.             flex-grow: 1;
  143.             background: #0a0a0a;
  144.             padding: 10px;
  145.             overflow-y: auto;
  146.             font-size: 0.9em;
  147.             color: #00ff88;
  148.             border-radius: 5px;
  149.             line-height: 1.6;
  150.             white-space: pre-wrap;
  151.             word-break: break-all;
  152.         }
  153.        
  154.         .terminal-line { animation: fadeIn 0.3s ease; }
  155.         .terminal-prime { color: #ffaa00; font-weight: bold; }
  156.         .terminal-info { color: #888; font-style: italic; }
  157.         .terminal-error { color: #ff3333; font-weight: bold; }
  158.  
  159.         @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  160.  
  161.         /* General UI Component Styles */
  162.         .display-card, .algorithm-info, .stats, .controls {
  163.             background: rgba(0, 0, 0, 0.5);
  164.             padding: 15px;
  165.             border-radius: 10px;
  166.             border: 1px solid rgba(255, 100, 0, 0.3);
  167.             text-align: center;
  168.         }
  169.  
  170.         #last-prime {
  171.             font-size: 2.5em;
  172.             color: #ffffff;
  173.             text-shadow: 0 0 20px rgba(255, 150, 0, 0.7);
  174.             word-break: break-all;
  175.         }
  176.  
  177.         #prime-count-display { font-size: 1.1em; color: #ffaa00; }
  178.         #algorithm-name { color: #ffff00; }
  179.         #equation-display { color: #00ffff; font-size: 0.9em; margin-top: 5px; }
  180.  
  181.         .progress-bar-container {
  182.             width: 100%; height: 30px; background: rgba(0, 0, 0, 0.5);
  183.             border-radius: 15px; overflow: hidden; position: relative;
  184.             border: 2px solid rgba(255, 100, 0, 0.3);
  185.         }
  186.  
  187.         #progress-bar {
  188.             height: 100%; width: 0%;
  189.             background: linear-gradient(90deg, #ff6600 0%, #ffaa00 50%, #ff3300 100%);
  190.             border-radius: 13px; transition: width 0.1s linear;
  191.         }
  192.  
  193.         #progress-text {
  194.             position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  195.             color: white; font-weight: bold; text-shadow: 1px 1px 2px black;
  196.         }
  197.  
  198.         .controls { display: flex; justify-content: center; gap: 15px; flex-wrap: wrap; }
  199.        
  200.         button {
  201.             padding: 10px 20px; font-size: 1em;
  202.             background: linear-gradient(135deg, #ff6600, #ffaa00);
  203.             color: #000; border: none; border-radius: 20px;
  204.             cursor: pointer; font-weight: bold; transition: all 0.3s ease;
  205.             box-shadow: 0 0 20px rgba(255, 100, 0, 0.3);
  206.         }
  207.         button:hover { transform: translateY(-2px); box-shadow: 0 5px 30px rgba(255, 100, 0, 0.5); }
  208.         button.paused { background: linear-gradient(135deg, #cc0066, #ff3399); }
  209.        
  210.         .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  211.         .stat-label { color: #888; font-size: 0.8em; }
  212.         .stat-value { color: #ffaa00; font-weight: bold; word-break: break-all; }
  213.        
  214.         .info-text { color: #888; font-size: 0.8em; margin-top: auto; }
  215.         input[type="file"] { display: none; }
  216.  
  217.         /* Scrollbar and Responsive Styles */
  218.         ::-webkit-scrollbar { width: 8px; }
  219.         ::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.3); }
  220.         ::-webkit-scrollbar-thumb { background: rgba(255, 100, 0, 0.5); border-radius: 4px; }
  221.  
  222.         @media (max-width: 1024px) {
  223.             body { align-items: flex-start; padding: 20px 0; height: auto; }
  224.             .container { grid-template-columns: 1fr; max-height: none; }
  225.             .terminal-container { height: 400px; }
  226.             h1 { font-size: 1.8em; }
  227.             #last-prime { font-size: 1.8em; }
  228.         }
  229.     </style>
  230. </head>
  231. <body>
  232.     <div class="phoenix-particles" id="phoenixParticles"></div>
  233.    
  234.     <div class="container">
  235.         <div class="main-panel">
  236.             <h1>🔥 The Prime Decider - Phoenix Edition 🔥</h1>
  237.            
  238.             <div class="display-card">
  239.                 <div id="last-prime">N/A</div>
  240.                 <div id="prime-count-display">Primes Found: 0</div>
  241.             </div>
  242.  
  243.             <div class="algorithm-info">
  244.                 <div id="algorithm-name">Awaiting Rebirth...</div>
  245.                 <div id="equation-display">...</div>
  246.             </div>
  247.  
  248.             <div class="progress-bar-container">
  249.                 <div id="progress-bar"></div>
  250.                 <div id="progress-text">Paused</div>
  251.             </div>
  252.  
  253.             <div class="controls">
  254.                 <button id="pause-button" onclick="togglePause()">Start</button>
  255.                 <button onclick="saveProgress()">💾 Save Phoenix</button>
  256.                 <button onclick="document.getElementById('fileInput').click()">📂 Load Phoenix</button>
  257.                 <input type="file" id="fileInput" accept=".txt" onchange="loadProgress(event)">
  258.             </div>
  259.  
  260.             <div class="stats">
  261.                 <div>
  262.                     <div class="stat-label">Currently Checking</div>
  263.                     <div class="stat-value" id="current-number">1</div>
  264.                 </div>
  265.                 <div>
  266.                     <div class="stat-label">Runtime</div>
  267.                     <div class="stat-value" id="runtime">00:00:00</div>
  268.                 </div>
  269.             </div>
  270.  
  271.             <div class="info-text">Press 'P' to Pause/Resume • Your hunt for primes is now eternal.</div>
  272.         </div>
  273.  
  274.         <div class="terminal-container">
  275.             <div class="terminal-header">
  276.                 <div class="terminal-title">&gt;_ Phoenix Terminal</div>
  277.             </div>
  278.             <div class="terminal-output" id="terminal-output"></div>
  279.         </div>
  280.     </div>
  281.  
  282.     <script>
  283.         // DOM Element References
  284.         const lastPrimeEl = document.getElementById('last-prime');
  285.         const primeCountDisplayEl = document.getElementById('prime-count-display');
  286.         const currentNumberEl = document.getElementById('current-number');
  287.         const algorithmNameEl = document.getElementById('algorithm-name');
  288.         const equationDisplayEl = document.getElementById('equation-display');
  289.         const progressBarEl = document.getElementById('progress-bar');
  290.         const progressTextEl = document.getElementById('progress-text');
  291.         const pauseButton = document.getElementById('pause-button');
  292.         const terminalOutputEl = document.getElementById('terminal-output');
  293.         const runtimeEl = document.getElementById('runtime');
  294.  
  295.         // State Management
  296.         let state = {
  297.             isPaused: true,
  298.             currentNumber: 1n,
  299.             primeCount: 0,
  300.             lastPrime: 'N/A',
  301.             algorithmIndex: 0,
  302.             startTime: null,
  303.             runtimeInterval: null,
  304.             primesFound: [], // Array to store primes for terminal and saving
  305.         };
  306.        
  307.         // =====================================================================
  308.         // ## Primality Testing Algorithms & Helpers
  309.        // =====================================================================
  310.        
  311.        function power(base, exp, mod) {
  312.            let res = 1n;
  313.             base %= mod;
  314.             while (exp > 0) {
  315.                 if (exp % 2n === 1n) res = (res * base) % mod;
  316.                 base = (base * base) % mod;
  317.                 exp /= 2n;
  318.             }
  319.             return res;
  320.         }
  321.  
  322.         const algorithms = [
  323.             { name: "Trial Division", equation: "n % i != 0 for i in [5, √n]", fn: function(n) {
  324.                 if (n <= 1n) return false; if (n <= 3n) return true;
  325.                if (n % 2n === 0n || n % 3n === 0n) return false;
  326.                for (let i = 5n; i * i <= n; i = i + 6n) {
  327.                    if (n % i === 0n || n % (i + 2n) === 0n) return false;
  328.                }
  329.                return true;
  330.            }},
  331.            { name: "Fermat's Little Theorem", equation: "a^(n-1) ≡ 1 (mod n)", fn: function(n, k = 5) {
  332.                if (n <= 1n || n === 4n) return false; if (n <= 3n) return true;
  333.                for (let i = 0; i < k; i++) {
  334.                    let a = 2n + BigInt(Math.floor(Math.random() * Number(n > 4n ? n - 4n : 1n)));
  335.                     if (power(a, n - 1n, n) !== 1n) return false;
  336.                 }
  337.                 return true;
  338.             }},
  339.             { name: "Miller-Rabin Test", equation: "Probabilistic check with witnesses", fn: function(n, k = 5) {
  340.                 if (n <= 1n || n === 4n) return false; if (n <= 3n) return true;
  341.                if (n % 2n === 0n) return false;
  342.                let d = n - 1n; while (d % 2n === 0n) d /= 2n;
  343.                for (let i = 0; i < k; i++) {
  344.                    let a = 2n + BigInt(Math.floor(Math.random() * Number(n > 4n ? n - 4n : 1n)));
  345.                     let x = power(a, d, n);
  346.                     if (x === 1n || x === n - 1n) continue;
  347.                     let isWitness = true;
  348.                     let dCopy = d;
  349.                     while (dCopy < n - 1n) {
  350.                       x = (x * x) % n;
  351.                       if (x === n - 1n) { isWitness = false; break; }
  352.                       dCopy *= 2n;
  353.                    }
  354.                    if (isWitness) return false;
  355.                }
  356.                return true;
  357.            }}
  358.        ];
  359.        const verificationAlgorithm = algorithms[0]; // Always verify with the most reliable
  360.  
  361.        // =====================================================================
  362.        // ## Core Application & UI Logic
  363.        // =====================================================================
  364.  
  365.        function addToTerminal(message, type = '') {
  366.            const line = document.createElement('div');
  367.            line.className = `terminal-line ${type}`;
  368.            if (type === 'terminal-prime') {
  369.                line.innerHTML = `&gt; New Prime Discovered: <span class="terminal-prime">${message.toLocaleString()}</span>`;
  370.             } else {
  371.                 line.textContent = `// ${message}`;
  372.             }
  373.             terminalOutputEl.appendChild(line);
  374.             terminalOutputEl.scrollTop = terminalOutputEl.scrollHeight;
  375.         }
  376.  
  377.         function updateUI() {
  378.             primeCountDisplayEl.textContent = `Primes Found: ${state.primeCount.toLocaleString()}`;
  379.             lastPrimeEl.textContent = typeof state.lastPrime === 'bigint' ? state.lastPrime.toLocaleString() : state.lastPrime;
  380.             currentNumberEl.textContent = state.currentNumber.toLocaleString();
  381.         }
  382.  
  383.         function updateRuntime() {
  384.             if (!state.startTime || state.isPaused) return;
  385.             const elapsed = Math.floor((Date.now() - state.startTime) / 1000);
  386.             const hours = String(Math.floor(elapsed / 3600)).padStart(2, '0');
  387.             const minutes = String(Math.floor((elapsed % 3600) / 60)).padStart(2, '0');
  388.             const seconds = String(elapsed % 60).padStart(2, '0');
  389.             runtimeEl.textContent = `${hours}:${minutes}:${seconds}`;
  390.         }
  391.        
  392.         function processNextNumber() {
  393.             if (state.isPaused) return;
  394.  
  395.             state.currentNumber++;
  396.             currentNumberEl.textContent = state.currentNumber.toLocaleString();
  397.  
  398.             const calculationAlgo = algorithms[state.algorithmIndex];
  399.             algorithmNameEl.textContent = `Calculating: ${calculationAlgo.name}`;
  400.             equationDisplayEl.textContent = calculationAlgo.equation;
  401.             progressTextEl.textContent = 'Calculating...';
  402.            
  403.             const isPotentiallyPrime = calculationAlgo.fn(state.currentNumber);
  404.            
  405.             // Animate first half (Calculation)
  406.             progressBarEl.style.width = '50%';
  407.            
  408.             setTimeout(() => {
  409.                 if (state.isPaused) return;
  410.                
  411.                 algorithmNameEl.textContent = `Verifying: ${verificationAlgorithm.name}`;
  412.                 progressTextEl.textContent = 'Error-Checking...';
  413.                 const isConfirmedPrime = verificationAlgorithm.fn(state.currentNumber);
  414.  
  415.                 // Animate second half (Verification)
  416.                 progressBarEl.style.width = '100%';
  417.  
  418.                 setTimeout(() => {
  419.                     if (state.isPaused) return;
  420.  
  421.                     if (isConfirmedPrime) {
  422.                         state.primeCount++;
  423.                         state.lastPrime = state.currentNumber;
  424.                         state.primesFound.push(state.currentNumber);
  425.                         addToTerminal(state.currentNumber, 'terminal-prime');
  426.                     }
  427.                    
  428.                     state.algorithmIndex = (state.algorithmIndex + 1) % algorithms.length;
  429.                     updateUI();
  430.                     progressBarEl.style.width = '0%';
  431.                    
  432.                     setTimeout(processNextNumber, 0); // Next cycle
  433.                 }, 200);
  434.             }, 200);
  435.         }
  436.        
  437.         function togglePause() {
  438.             state.isPaused = !state.isPaused;
  439.             if (state.isPaused) {
  440.                 pauseButton.textContent = 'Resume';
  441.                 pauseButton.classList.add('paused');
  442.                 progressTextEl.textContent = 'Paused';
  443.                 algorithmNameEl.textContent = 'Calculations Paused';
  444.             } else {
  445.                 if (state.startTime === null) { // First start
  446.                     state.startTime = Date.now();
  447.                     state.runtimeInterval = setInterval(updateRuntime, 1000);
  448.                 }
  449.                 pauseButton.textContent = 'Pause';
  450.                 pauseButton.classList.remove('paused');
  451.                 updateUI();
  452.                 processNextNumber();
  453.             }
  454.         }
  455.        
  456.         // =====================================================================
  457.         // ## Save & Load "Phoenix State" Logic
  458.        // =====================================================================
  459.  
  460.        function saveProgress() {
  461.            if (state.primesFound.length === 0) {
  462.                addToTerminal("No primes to save.", "terminal-error");
  463.                 return;
  464.             }
  465.             const wasPaused = state.isPaused;
  466.             if (!wasPaused) togglePause(); // Pause to prevent data race
  467.  
  468.             const fileContent = state.primesFound.join('\t');
  469.             const blob = new Blob([fileContent], { type: 'text/plain;charset=utf-8' });
  470.             const a = document.createElement('a');
  471.             a.href = URL.createObjectURL(blob);
  472.             a.download = `prime_decider_phoenix_save_${Date.now()}.txt`;
  473.             document.body.appendChild(a);
  474.             a.click();
  475.             document.body.removeChild(a);
  476.             URL.revokeObjectURL(a.href);
  477.             addToTerminal("Phoenix state saved to file.");
  478.  
  479.             if (!wasPaused) togglePause(); // Resume if it was running
  480.         }
  481.        
  482.         function loadProgress(event) {
  483.             const file = event.target.files[0];
  484.             if (!file) return;
  485.  
  486.             if (!state.isPaused) togglePause(); // Force pause during load
  487.            
  488.             const reader = new FileReader();
  489.             reader.onload = (e) => {
  490.                 try {
  491.                     const content = e.target.result;
  492.                     const primeStrings = content.split('\t').filter(s => s.trim() !== '');
  493.                    
  494.                     if (primeStrings.length === 0) throw new Error("File is empty or invalid.");
  495.  
  496.                     // Reset and load new state
  497.                     terminalOutputEl.innerHTML = '';
  498.                     addToTerminal(`Phoenix rising from ashes of '${file.name}'...`);
  499.                    
  500.                     const loadedPrimes = primeStrings.map(s => BigInt(s.trim()));
  501.                    
  502.                     state.primesFound = loadedPrimes;
  503.                     state.primeCount = loadedPrimes.length;
  504.                     state.lastPrime = loadedPrimes[loadedPrimes.length - 1];
  505.                     state.currentNumber = state.lastPrime;
  506.                    
  507.                     // Repopulate terminal (show last 100 for performance)
  508.                     const displayPrimes = loadedPrimes.slice(-100);
  509.                     addToTerminal(`Loaded ${loadedPrimes.length} primes. Displaying last ${displayPrimes.length}.`);
  510.                     displayPrimes.forEach(p => addToTerminal(p, 'terminal-prime'));
  511.  
  512.                     updateUI();
  513.                     addToTerminal(`Ready to seek primes after ${state.lastPrime.toLocaleString()}.`);
  514.                 } catch (error) {
  515.                     addToTerminal(`Error loading file: ${error.message}`, 'terminal-error');
  516.                     console.error("Load error:", error);
  517.                 } finally {
  518.                     // Reset the file input to allow loading the same file again
  519.                     event.target.value = '';
  520.                 }
  521.             };
  522.             reader.readAsText(file);
  523.         }
  524.  
  525.         // =====================================================================
  526.         // ## Initialization
  527.         // =====================================================================
  528.        
  529.         function generatePhoenixParticles() {
  530.             const container = document.getElementById('phoenixParticles');
  531.             for (let i = 0; i < 30; i++) {
  532.                const particle = document.createElement('div');
  533.                particle.className = 'phoenix-particle';
  534.                particle.style.left = `${Math.random() * 100}%`;
  535.                particle.style.animationDelay = `${Math.random() * 4}s`;
  536.                particle.style.animationDuration = `${2 + Math.random() * 3}s`;
  537.                container.appendChild(particle);
  538.            }
  539.        }
  540.        
  541.        window.onload = () => {
  542.             generatePhoenixParticles();
  543.             addToTerminal("Phoenix Prime Decider initialized...");
  544.             addToTerminal("Awaiting the command to rise.");
  545.             updateUI();
  546.         };
  547.  
  548.         window.addEventListener('keydown', (e) => {
  549.             if (e.key.toLowerCase() === 'p') {
  550.                 e.preventDefault();
  551.                 togglePause();
  552.             }
  553.         });
  554.     </script>
  555. </body>
  556. </html>
  557.  
Advertisement
Add Comment
Please, Sign In to add comment