Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>The Prime Decider - Phoenix Edition</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- body {
- font-family: 'Courier New', monospace;
- background: linear-gradient(135deg, #0a0a0a 0%, #1a0033 50%, #330066 100%);
- color: #00ff88;
- min-height: 100vh;
- display: flex;
- justify-content: center;
- align-items: center;
- overflow: hidden;
- position: relative;
- }
- body::before {
- content: '';
- position: absolute;
- width: 200%;
- height: 200%;
- background:
- radial-gradient(circle at 20% 80%, rgba(255, 100, 0, 0.15) 0%, transparent 50%),
- radial-gradient(circle at 80% 20%, rgba(255, 200, 0, 0.15) 0%, transparent 50%),
- radial-gradient(circle at 40% 40%, rgba(255, 50, 0, 0.1) 0%, transparent 50%);
- animation: phoenixFloat 25s ease-in-out infinite;
- }
- @keyframes phoenixFloat {
- 0%, 100% { transform: translate(0, 0) rotate(0deg) scale(1); }
- 25% { transform: translate(-30px, -30px) rotate(90deg) scale(1.1); }
- 50% { transform: translate(30px, -50px) rotate(180deg) scale(0.95); }
- 75% { transform: translate(-20px, 20px) rotate(270deg) scale(1.05); }
- }
- .phoenix-particles {
- position: absolute;
- width: 100%;
- height: 100%;
- overflow: hidden;
- pointer-events: none;
- }
- .phoenix-particle {
- position: absolute;
- width: 4px;
- height: 4px;
- background: radial-gradient(circle, rgba(255, 150, 0, 0.8), transparent);
- animation: rise 4s linear infinite;
- }
- @keyframes rise {
- 0% {
- transform: translateY(100vh) scale(0);
- opacity: 0;
- }
- 10% {
- opacity: 1;
- }
- 90% {
- opacity: 1;
- }
- 100% {
- transform: translateY(-100vh) scale(1.5);
- opacity: 0;
- }
- }
- .container {
- background: rgba(10, 10, 30, 0.95);
- border-radius: 20px;
- padding: 30px;
- box-shadow:
- 0 0 100px rgba(255, 100, 0, 0.3),
- inset 0 0 50px rgba(255, 150, 0, 0.1);
- border: 2px solid rgba(255, 100, 0, 0.4);
- max-width: 1200px;
- width: 95%;
- position: relative;
- z-index: 10;
- display: grid;
- grid-template-columns: 1fr 400px;
- gap: 30px;
- max-height: 90vh;
- overflow: hidden;
- }
- .main-panel {
- display: flex;
- flex-direction: column;
- gap: 20px;
- }
- h1 {
- text-align: center;
- font-size: 2.2em;
- text-shadow:
- 0 0 20px #ff6600,
- 0 0 40px #ff3300,
- 0 0 60px #ff0000;
- animation: phoenixPulse 3s ease-in-out infinite;
- background: linear-gradient(45deg, #ff6600, #ffaa00, #ff3300);
- -webkit-background-clip: text;
- -webkit-text-fill-color: transparent;
- background-clip: text;
- }
- @keyframes phoenixPulse {
- 0%, 100% { filter: brightness(1); transform: scale(1); }
- 50% { filter: brightness(1.3); transform: scale(1.02); }
- }
- .terminal-container {
- background: #000000;
- border: 2px solid rgba(255, 100, 0, 0.5);
- border-radius: 10px;
- padding: 15px;
- display: flex;
- flex-direction: column;
- height: calc(90vh - 60px);
- box-shadow:
- inset 0 0 20px rgba(255, 100, 0, 0.2),
- 0 0 30px rgba(255, 100, 0, 0.1);
- }
- .terminal-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding-bottom: 10px;
- border-bottom: 1px solid rgba(255, 100, 0, 0.3);
- margin-bottom: 10px;
- }
- .terminal-title {
- color: #ffaa00;
- font-size: 1.1em;
- text-shadow: 0 0 10px rgba(255, 150, 0, 0.5);
- }
- .terminal-controls {
- display: flex;
- gap: 10px;
- }
- .terminal-btn {
- padding: 5px 12px;
- font-size: 0.85em;
- background: linear-gradient(135deg, #ff6600, #ff9900);
- color: #000;
- border: none;
- border-radius: 5px;
- cursor: pointer;
- font-weight: bold;
- transition: all 0.3s ease;
- }
- .terminal-btn:hover {
- transform: translateY(-2px);
- box-shadow: 0 5px 15px rgba(255, 100, 0, 0.4);
- }
- .terminal-output {
- flex: 1;
- background: #0a0a0a;
- padding: 10px;
- overflow-y: auto;
- font-family: 'Courier New', monospace;
- font-size: 0.9em;
- color: #00ff00;
- border-radius: 5px;
- line-height: 1.6;
- }
- .terminal-line {
- margin: 2px 0;
- padding: 2px 5px;
- transition: background 0.3s;
- }
- .terminal-line:hover {
- background: rgba(255, 150, 0, 0.1);
- }
- .terminal-prime {
- color: #ffaa00;
- font-weight: bold;
- }
- .terminal-info {
- color: #888;
- font-style: italic;
- }
- .terminal-stats {
- padding: 10px;
- border-top: 1px solid rgba(255, 100, 0, 0.3);
- color: #ffaa00;
- font-size: 0.85em;
- }
- .prime-display {
- background: rgba(0, 0, 0, 0.7);
- padding: 15px;
- border-radius: 10px;
- border: 1px solid rgba(255, 100, 0, 0.5);
- }
- .current-prime {
- font-size: 1.8em;
- text-align: center;
- margin-bottom: 10px;
- color: #ffffff;
- text-shadow: 0 0 20px rgba(255, 150, 0, 0.7);
- }
- .prime-count {
- text-align: center;
- font-size: 1.1em;
- color: #ffaa00;
- }
- .algorithm-info {
- background: rgba(50, 20, 0, 0.3);
- padding: 12px;
- border-radius: 8px;
- border: 1px solid rgba(255, 150, 0, 0.3);
- }
- .algorithm-name {
- font-size: 1em;
- color: #ffff00;
- margin-bottom: 5px;
- }
- .algorithm-equation {
- font-family: 'Courier New', monospace;
- color: #00ffff;
- font-size: 0.85em;
- word-break: break-all;
- padding: 8px;
- background: rgba(0, 0, 0, 0.5);
- border-radius: 5px;
- margin-top: 8px;
- }
- .loading-container {
- margin: 15px 0;
- }
- .loading-bar-bg {
- width: 100%;
- height: 35px;
- background: rgba(0, 0, 0, 0.5);
- border-radius: 20px;
- overflow: hidden;
- position: relative;
- border: 2px solid rgba(255, 100, 0, 0.3);
- }
- .loading-bar {
- height: 100%;
- width: 0%;
- background: linear-gradient(90deg,
- #ff6600 0%,
- #ffaa00 50%,
- #ff3300 100%);
- border-radius: 18px;
- transition: width 0.1s linear;
- position: relative;
- overflow: hidden;
- }
- .loading-bar::after {
- content: '';
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: linear-gradient(90deg,
- transparent,
- rgba(255, 255, 255, 0.4),
- transparent);
- animation: shimmer 1.5s infinite;
- }
- @keyframes shimmer {
- 0% { transform: translateX(-100%); }
- 100% { transform: translateX(100%); }
- }
- .loading-label {
- text-align: center;
- margin-top: 8px;
- font-size: 0.85em;
- }
- .phase-indicator {
- display: inline-block;
- padding: 2px 8px;
- border-radius: 5px;
- margin-left: 10px;
- font-size: 0.8em;
- }
- .phase-calculating {
- background: rgba(255, 150, 0, 0.2);
- color: #ffaa00;
- }
- .phase-checking {
- background: rgba(255, 50, 0, 0.2);
- color: #ff6600;
- }
- .controls {
- display: flex;
- justify-content: center;
- gap: 15px;
- flex-wrap: wrap;
- }
- button {
- padding: 10px 25px;
- font-size: 1em;
- background: linear-gradient(135deg, #ff6600, #ffaa00);
- color: #000;
- border: none;
- border-radius: 25px;
- cursor: pointer;
- font-weight: bold;
- transition: all 0.3s ease;
- box-shadow: 0 0 20px rgba(255, 100, 0, 0.3);
- }
- button:hover {
- transform: translateY(-2px);
- box-shadow: 0 5px 30px rgba(255, 100, 0, 0.5);
- }
- button:active {
- transform: translateY(0);
- }
- button.paused {
- background: linear-gradient(135deg, #ff0088, #ff00ff);
- box-shadow: 0 0 20px rgba(255, 0, 136, 0.3);
- }
- .stats {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- gap: 10px;
- }
- .stat-card {
- background: rgba(0, 0, 0, 0.5);
- padding: 10px;
- border-radius: 8px;
- border: 1px solid rgba(255, 100, 0, 0.2);
- }
- .stat-label {
- color: #888;
- font-size: 0.75em;
- margin-bottom: 3px;
- }
- .stat-value {
- color: #ffaa00;
- font-size: 1em;
- font-weight: bold;
- }
- .info-text {
- text-align: center;
- margin-top: 10px;
- color: #888;
- font-size: 0.8em;
- }
- ::-webkit-scrollbar {
- width: 8px;
- }
- ::-webkit-scrollbar-track {
- background: rgba(0, 0, 0, 0.3);
- border-radius: 4px;
- }
- ::-webkit-scrollbar-thumb {
- background: rgba(255, 100, 0, 0.5);
- border-radius: 4px;
- }
- ::-webkit-scrollbar-thumb:hover {
- background: rgba(255, 150, 0, 0.7);
- }
- input[type="file"] {
- display: none;
- }
- @media (max-width: 1024px) {
- .container {
- grid-template-columns: 1fr;
- max-width: 95%;
- }
- .terminal-container {
- height: 300px;
- }
- }
- </style>
- </head>
- <body>
- <div class="phoenix-particles" id="phoenixParticles"></div>
- <div class="container">
- <div class="main-panel">
- <h1>🔥 The Prime Decider - Phoenix Edition 🔥</h1>
- <div class="prime-display">
- <div class="current-prime" id="currentPrime">7</div>
- <div class="prime-count">Prime #<span id="primeCount">4</span></div>
- </div>
- <div class="algorithm-info">
- <div class="algorithm-name">Current Algorithm: <span id="algorithmName">Trial Division</span></div>
- <div class="algorithm-equation" id="algorithmEquation">n % d !== 0 for all d ≤ √n</div>
- </div>
- <div class="loading-container">
- <div class="loading-bar-bg">
- <div class="loading-bar" id="loadingBar"></div>
- </div>
- <div class="loading-label">
- <span id="loadingPhase">Calculating</span>
- <span class="phase-indicator phase-calculating" id="phaseIndicator">Computing</span>
- </div>
- </div>
- <div class="controls">
- <button id="pauseBtn" onclick="togglePause()">Pause</button>
- <button onclick="saveProgress()">🔥 Save Phoenix</button>
- <button onclick="document.getElementById('fileInput').click()">🔥 Load Phoenix</button>
- <button onclick="clearTerminal()">Clear Terminal</button>
- <input type="file" id="fileInput" accept=".txt" onchange="loadProgress(event)">
- </div>
- <div class="stats">
- <div class="stat-card">
- <div class="stat-label">Started From</div>
- <div class="stat-value" id="startedFrom">7</div>
- </div>
- <div class="stat-card">
- <div class="stat-label">Current Number</div>
- <div class="stat-value" id="currentNumber">7</div>
- </div>
- <div class="stat-card">
- <div class="stat-label">Primes Found</div>
- <div class="stat-value" id="totalPrimes">4</div>
- </div>
- <div class="stat-card">
- <div class="stat-label">Numbers Checked</div>
- <div class="stat-value" id="numbersChecked">7</div>
- </div>
- <div class="stat-card">
- <div class="stat-label">Algorithm Cycles</div>
- <div class="stat-value" id="algorithmCycles">0</div>
- </div>
- <div class="stat-card">
- <div class="stat-label">Runtime</div>
- <div class="stat-value" id="runtime">00:00:00</div>
- </div>
- </div>
- <div class="info-text">
- Press 'P' to pause/resume • Save/Load your eternal Prime hunt • Phoenix rises from the ashes!
- </div>
- </div>
- <div class="terminal-container">
- <div class="terminal-header">
- <div class="terminal-title">🔥 Phoenix Terminal Output</div>
- <div class="terminal-controls">
- <button class="terminal-btn" onclick="exportTerminal()">Export</button>
- <button class="terminal-btn" onclick="scrollToBottom()">Bottom</button>
- </div>
- </div>
- <div class="terminal-output" id="terminalOutput">
- <div class="terminal-line terminal-info">// Phoenix Prime Decider initialized...</div>
- <div class="terminal-line terminal-info">// Starting from sacred number 7...</div>
- <div class="terminal-line terminal-info">// Initial primes loaded: 2, 3, 5, 7</div>
- </div>
- <div class="terminal-stats" id="terminalStats">
- Total Terminal Entries: <span id="terminalCount">3</span>
- </div>
- </div>
- </div>
- <script>
- // Phoenix particles
- function createPhoenixParticles() {
- const container = document.getElementById('phoenixParticles');
- for (let i = 0; i < 30; i++) {
- const particle = document.createElement('div');
- particle.className = 'phoenix-particle';
- particle.style.left = Math.random() * 100 + '%';
- particle.style.animationDelay = Math.random() * 4 + 's';
- particle.style.animationDuration = (3 + Math.random() * 3) + 's';
- container.appendChild(particle);
- }
- }
- // Prime calculation state
- let isPaused = false;
- let currentNum = 7;
- let primeCount = 4;
- let totalChecked = 7;
- let algorithmCycles = 0;
- let startTime = Date.now();
- let knownPrimes = [2, 3, 5, 7];
- let currentAlgorithm = 0;
- let progress = 0;
- let isChecking = false;
- let terminalLines = [];
- let sessionStartTime = new Date().toISOString();
- // Algorithm definitions
- const algorithms = [
- {
- name: "Trial Division",
- equation: "n % d !== 0 for all d ≤ √n",
- check: trialDivision
- },
- {
- name: "6k ± 1 Optimization",
- equation: "Check n = 6k ± 1, then n % p !== 0 for primes p ≤ √n",
- check: sixKOptimization
- },
- {
- name: "Miller-Rabin Probabilistic",
- equation: "n-1 = 2^r × d, check a^d ≡ 1 (mod n) or a^(2^i×d) ≡ -1 (mod n)",
- check: millerRabin
- },
- {
- name: "Fermat's Little Theorem",
- equation: "a^(n-1) ≡ 1 (mod n) for coprime a",
- check: fermatTest
- },
- {
- name: "Solovay-Strassen",
- equation: "a^((n-1)/2) ≡ (a/n) (mod n) where (a/n) is Jacobi symbol",
- check: solovayStrassen
- },
- {
- name: "Wheel Factorization",
- equation: "Skip multiples of 2,3,5: check n = 30k + r where r ∈ {1,7,11,13,17,19,23,29}",
- check: wheelFactorization
- },
- {
- name: "Sieve-based Check",
- equation: "Use cached primes: n % p !== 0 for all cached primes p ≤ √n",
- check: sieveBasedCheck
- }
- ];
- // Algorithm implementations
- function trialDivision(n) {
- if (n <= 1) return false;
- if (n <= 3) return true;
- if (n % 2 === 0 || n % 3 === 0) return false;
- for (let i = 5; i * i <= n; i += 6) {
- if (n % i === 0 || n % (i + 2) === 0) return false;
- }
- return true;
- }
- function sixKOptimization(n) {
- if (n <= 1) return false;
- if (n <= 3) return true;
- if (n % 2 === 0 || n % 3 === 0) return false;
- let limit = Math.sqrt(n);
- for (let i = 5; i <= limit; i += 6) {
- if (n % i === 0 || n % (i + 2) === 0) return false;
- }
- return true;
- }
- function modPow(base, exp, mod) {
- let result = 1n;
- base = BigInt(base) % BigInt(mod);
- exp = BigInt(exp);
- mod = BigInt(mod);
- while (exp > 0n) {
- if (exp % 2n === 1n) {
- result = (result * base) % mod;
- }
- exp = exp >> 1n;
- base = (base * base) % mod;
- }
- return Number(result);
- }
- function millerRabin(n, k = 5) {
- if (n <= 1) return false;
- if (n === 2 || n === 3) return true;
- if (n % 2 === 0) return false;
- let r = 0;
- let d = n - 1;
- while (d % 2 === 0) {
- d /= 2;
- r++;
- }
- for (let i = 0; i < k; i++) {
- let a = 2 + Math.floor(Math.random() * (n - 4));
- let x = modPow(a, d, n);
- if (x === 1 || x === n - 1) continue;
- let continueWitness = false;
- for (let j = 0; j < r - 1; j++) {
- x = modPow(x, 2, n);
- if (x === n - 1) {
- continueWitness = true;
- break;
- }
- }
- if (!continueWitness) return false;
- }
- return true;
- }
- function fermatTest(n, k = 5) {
- if (n <= 1) return false;
- if (n <= 3) return true;
- if (n % 2 === 0) return false;
- for (let i = 0; i < k; i++) {
- let a = 2 + Math.floor(Math.random() * (n - 4));
- if (modPow(a, n - 1, n) !== 1) return false;
- }
- return true;
- }
- function jacobiSymbol(a, n) {
- if (n <= 0 || n % 2 === 0) return 0;
- a = a % n;
- let result = 1;
- while (a !== 0) {
- while (a % 2 === 0) {
- a /= 2;
- let r = n % 8;
- if (r === 3 || r === 5) result = -result;
- }
- [a, n] = [n, a];
- if (a % 4 === 3 && n % 4 === 3) result = -result;
- a = a % n;
- }
- return n === 1 ? result : 0;
- }
- function solovayStrassen(n, k = 5) {
- if (n <= 1) return false;
- if (n === 2 || n === 3) return true;
- if (n % 2 === 0) return false;
- for (let i = 0; i < k; i++) {
- let a = 2 + Math.floor(Math.random() * (n - 3));
- let jacobi = jacobiSymbol(a, n) % n;
- if (jacobi < 0) jacobi += n;
- if (jacobi === 0 || modPow(a, (n - 1) / 2, n) !== jacobi) {
- return false;
- }
- }
- return true;
- }
- function wheelFactorization(n) {
- if (n <= 1) return false;
- if (n === 2 || n === 3 || n === 5) return true;
- if (n % 2 === 0 || n % 3 === 0 || n % 5 === 0) return false;
- const wheel = [1, 7, 11, 13, 17, 19, 23, 29];
- let w = 30;
- let limit = Math.sqrt(n);
- for (let k = 0; k * w <= limit; k++) {
- for (let r of wheel) {
- let d = k * w + r;
- if (d > 1 && d <= limit && n % d === 0) return false;
- }
- }
- return true;
- }
- function sieveBasedCheck(n) {
- if (n <= 1) return false;
- for (let prime of knownPrimes) {
- if (prime * prime > n) break;
- if (n % prime === 0) return n === prime;
- }
- return true;
- }
- // Error checking using different algorithm
- function errorCheck(n, primaryResult) {
- let verifyAlg = (currentAlgorithm + 3) % algorithms.length;
- return algorithms[verifyAlg].check(n) === primaryResult;
- }
- // Terminal functions
- function addToTerminal(message, type = 'info') {
- const terminal = document.getElementById('terminalOutput');
- const timestamp = new Date().toISOString();
- const line = document.createElement('div');
- line.className = `terminal-line terminal-${type}`;
- if (type === 'prime') {
- line.innerHTML = `<span style="color: #666;">[${timestamp}]</span> <span class="terminal-prime">PRIME FOUND: ${message}</span>`;
- terminalLines.push({
- timestamp: timestamp,
- prime: parseInt(message),
- index: primeCount
- });
- } else {
- line.innerHTML = `<span style="color: #666;">[${timestamp}]</span> ${message}`;
- }
- terminal.appendChild(line);
- updateTerminalStats();
- // Auto-scroll to bottom
- terminal.scrollTop = terminal.scrollHeight;
- }
- function updateTerminalStats() {
- const count = document.getElementById('terminalOutput').children.length;
- document.getElementById('terminalCount').textContent = count;
- }
- function clearTerminal() {
- const terminal = document.getElementById('terminalOutput');
- terminal.innerHTML = '<div class="terminal-line terminal-info">// Terminal cleared - Phoenix rises anew...</div>';
- updateTerminalStats();
- }
- function scrollToBottom() {
- const terminal = document.getElementById('terminalOutput');
- terminal.scrollTop = terminal.scrollHeight;
- }
- function exportTerminal() {
- let content = `PHOENIX PRIME DECIDER - TERMINAL EXPORT\n`;
- content += `Session Started: ${sessionStartTime}\n`;
- content += `Export Time: ${new Date().toISOString()}\n`;
- content += `Total Primes Found: ${primeCount}\n`;
- content += `========================================\n\n`;
- // Export in tab-delimited format
- content += `INDEX\tPRIME\tTIMESTAMP\n`;
- terminalLines.forEach(line => {
- content += `${line.index}\t${line.prime}\t${line.timestamp}\n`;
- });
- const blob = new Blob([content], { type: 'text/plain' });
- const url = window.URL.createObjectURL(blob);
- const a = document.createElement('a');
- a.href = url;
- a.download = `phoenix_primes_${Date.now()}.txt`;
- a.click();
- window.URL.revokeObjectURL(url);
- addToTerminal('// Terminal exported to file', 'info');
- }
- // Save/Load functions
- function saveProgress() {
- const saveData = {
- version: "1.0",
- timestamp: new Date().toISOString(),
- currentNum: currentNum,
- primeCount: primeCount,
- totalChecked: totalChecked,
- algorithmCycles: algorithmCycles,
- knownPrimes: knownPrimes,
- terminalLines: terminalLines,
- sessionStartTime: sessionStartTime
- };
- let content = `PHOENIX PRIME DECIDER - SAVE FILE v1.0\n`;
- content += `Saved: ${saveData.timestamp}\n`;
- content += `Current: ${currentNum}\n`;
- content += `Count: ${primeCount}\n`;
- content += `Checked: ${totalChecked}\n`;
- content += `Cycles: ${algorithmCycles}\n`;
- content += `Session: ${sessionStartTime}\n`;
- content += `========================================\n`;
- content += `INDEX\tPRIME\tTIMESTAMP\n`;
- terminalLines.forEach(line => {
- content += `${line.index}\t${line.prime}\t${line.timestamp}\n`;
- });
- const blob = new Blob([content], { type: 'text/plain' });
- const url = window.URL.createObjectURL(blob);
- const a = document.createElement('a');
- a.href = url;
- a.download = `phoenix_save_${Date.now()}.txt`;
- a.click();
- window.URL.revokeObjectURL(url);
- addToTerminal(`// Phoenix state saved! Primes: ${primeCount}, Current: ${currentNum}`, 'info');
- }
- function loadProgress(event) {
- const file = event.target.files[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = function(e) {
- try {
- const content = e.target.result;
- const lines = content.split('\n');
- // Parse header information
- let loadedData = {
- currentNum: 7,
- primeCount: 0,
- totalChecked: 7,
- algorithmCycles: 0,
- primes: []
- };
- // Parse metadata from header
- lines.forEach((line, index) => {
- if (line.startsWith('Current:')) {
- loadedData.currentNum = parseInt(line.split(':')[1].trim());
- } else if (line.startsWith('Count:')) {
- loadedData.primeCount = parseInt(line.split(':')[1].trim());
- } else if (line.startsWith('Checked:')) {
- loadedData.totalChecked = parseInt(line.split(':')[1].trim());
- } else if (line.startsWith('Cycles:')) {
- loadedData.algorithmCycles = parseInt(line.split(':')[1].trim());
- }
- });
- // Find the data section (after the separator)
- let dataStartIndex = lines.findIndex(line => line.includes('INDEX\tPRIME\tTIMESTAMP'));
- if (dataStartIndex !== -1) {
- // Clear terminal and add loaded primes
- clearTerminal();
- addToTerminal('// Phoenix rises from the ashes! Loading saved state...', 'info');
- terminalLines = [];
- knownPrimes = [2, 3, 5, 7]; // Reset to initial primes
- // Parse and load all primes
- for (let i = dataStartIndex + 1; i < lines.length; i++) {
- const line = lines[i].trim();
- if (line && !line.startsWith('//')) {
- const parts = line.split('\t');
- if (parts.length >= 2) {
- const index = parseInt(parts[0]);
- const prime = parseInt(parts[1]);
- const timestamp = parts[2] || new Date().toISOString();
- if (!isNaN(prime) && prime > 7) {
- knownPrimes.push(prime);
- terminalLines.push({
- timestamp: timestamp,
- prime: prime,
- index: index
- });
- // Add to terminal display
- const terminalLine = document.createElement('div');
- terminalLine.className = 'terminal-line terminal-prime';
- terminalLine.innerHTML = `<span style="color: #666;">[${timestamp}]</span> <span class="terminal-prime">PRIME FOUND: ${prime}</span>`;
- document.getElementById('terminalOutput').appendChild(terminalLine);
- }
- }
- }
- }
- // Update state from loaded data
- currentNum = loadedData.currentNum || knownPrimes[knownPrimes.length - 1];
- primeCount = loadedData.primeCount || knownPrimes.length;
- totalChecked = loadedData.totalChecked || currentNum;
- algorithmCycles = loadedData.algorithmCycles || 0;
- // Update display
- updateDisplay();
- updateTerminalStats();
- addToTerminal(`// Phoenix restored! Loaded ${primeCount} primes, continuing from ${currentNum}`, 'info');
- addToTerminal(`// Last prime discovered: ${knownPrimes[knownPrimes.length - 1]}`, 'info');
- // Update starting point display
- document.getElementById('startedFrom').textContent = currentNum.toLocaleString();
- // Resume if not paused
- if (!isPaused) {
- setTimeout(calculateNextPrime, 1000);
- }
- } else {
- addToTerminal('// Error: Invalid save file format', 'info');
- }
- } catch (error) {
- console.error('Load error:', error);
- addToTerminal('// Error loading save file: ' + error.message, 'info');
- }
- };
- reader.readAsText(file);
- event.target.value = ''; // Reset file input
- }
- // Update display
- function updateDisplay() {
- document.getElementById('currentPrime').textContent = knownPrimes[knownPrimes.length - 1].toLocaleString();
- document.getElementById('primeCount').textContent = primeCount.toLocaleString();
- document.getElementById('currentNumber').textContent = currentNum.toLocaleString();
- document.getElementById('totalPrimes').textContent = primeCount.toLocaleString();
- document.getElementById('numbersChecked').textContent = totalChecked.toLocaleString();
- document.getElementById('algorithmCycles').textContent = algorithmCycles.toLocaleString();
- }
- // Update runtime
- function updateRuntime() {
- let elapsed = Date.now() - startTime;
- let hours = Math.floor(elapsed / 3600000);
- let minutes = Math.floor((elapsed % 3600000) / 60000);
- let seconds = Math.floor((elapsed % 60000) / 1000);
- document.getElementById('runtime').textContent =
- `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
- }
- // Main calculation loop
- async function calculateNextPrime() {
- if (isPaused) return;
- currentNum++;
- totalChecked++;
- // Special check for 21
- if (currentNum === 21) {
- addToTerminal(`// Checking sacred number 21... (3 × 7 = not prime)`, 'info');
- }
- // Select algorithm (rotate every 100 numbers)
- if (totalChecked % 100 === 0) {
- currentAlgorithm = (currentAlgorithm + 1) % algorithms.length;
- algorithmCycles++;
- document.getElementById('algorithmName').textContent = algorithms[currentAlgorithm].name;
- document.getElementById('algorithmEquation').textContent = algorithms[currentAlgorithm].equation;
- addToTerminal(`// Algorithm switched to: ${algorithms[currentAlgorithm].name}`, 'info');
- }
- // Simulate calculation phase (0-50%)
- for (let i = 0; i <= 50; i += 2) {
- if (isPaused) return;
- progress = i;
- document.getElementById('loadingBar').style.width = progress + '%';
- document.getElementById('loadingPhase').textContent = 'Calculating';
- document.getElementById('phaseIndicator').textContent = 'Computing';
- document.getElementById('phaseIndicator').className = 'phase-indicator phase-calculating';
- await new Promise(resolve => setTimeout(resolve, 10));
- }
- // Perform actual prime check
- let isPrime = algorithms[currentAlgorithm].check(currentNum);
- // Error checking phase (50-100%)
- isChecking = true;
- for (let i = 50; i <= 100; i += 2) {
- if (isPaused) return;
- progress = i;
- document.getElementById('loadingBar').style.width = progress + '%';
- document.getElementById('loadingPhase').textContent = 'Error Checking';
- document.getElementById('phaseIndicator').textContent = 'Verifying';
- document.getElementById('phaseIndicator').className = 'phase-indicator phase-checking';
- await new Promise(resolve => setTimeout(resolve, 10));
- }
- // Verify with error checking
- let isVerified = errorCheck(currentNum, isPrime);
- if (isPrime && isVerified) {
- primeCount++;
- knownPrimes.push(currentNum);
- // Add to terminal
- addToTerminal(currentNum.toLocaleString(), 'prime');
- // Keep only last 1000 primes in memory for performance
- if (knownPrimes.length > 1000) {
- knownPrimes = knownPrimes.slice(-1000);
- }
- updateDisplay();
- }
- // Reset progress bar
- progress = 0;
- document.getElementById('loadingBar').style.width = '0%';
- isChecking = false;
- // Continue to next number
- setTimeout(calculateNextPrime, 1);
- }
- // Pause/Resume functionality
- function togglePause() {
- isPaused = !isPaused;
- const btn = document.getElementById('pauseBtn');
- btn.textContent = isPaused ? 'Resume' : 'Pause';
- btn.className = isPaused ? 'paused' : '';
- if (!isPaused) {
- addToTerminal('// Phoenix awakens! Resuming prime hunt...', 'info');
- calculateNextPrime();
- } else {
- addToTerminal('// Phoenix rests... Prime hunt paused', 'info');
- }
- }
- // Keyboard controls
- document.addEventListener('keydown', (e) => {
- if (e.key.toLowerCase() === 'p') {
- togglePause();
- }
- });
- // Initialize special starting points
- function initializeWithSpecialPrimes() {
- // Ensure we include 21 in our checks even though it's not prime
- if (!knownPrimes.includes(21)) {
- currentNum = 20; // Start just before 21 to ensure it's checked
- }
- }
- // Start the application
- window.onload = () => {
- createPhoenixParticles();
- initializeWithSpecialPrimes();
- updateDisplay();
- setInterval(updateRuntime, 1000);
- addToTerminal('// Phoenix Prime Decider fully initialized!', 'info');
- addToTerminal('// Press "P" or click Pause to control the hunt', 'info');
- addToTerminal('// Save your progress to resurrect later!', 'info');
- calculateNextPrime();
- };
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment