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>
- body {
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- max-width: 1000px;
- margin: 0 auto;
- padding: 20px;
- background-color: #0d1117;
- color: #c9d1d9;
- line-height: 1.6;
- }
- h1 {
- color: #58a6ff;
- text-align: center;
- border-bottom: 2px solid #30363d;
- padding-bottom: 10px;
- margin-bottom: 20px;
- }
- .container {
- background-color: #161b22;
- border-radius: 8px;
- padding: 20px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
- margin-bottom: 20px;
- }
- .prime-display {
- font-size: 2.5em;
- text-align: center;
- margin: 20px 0;
- color: #7ee787;
- font-weight: bold;
- }
- .loading-container {
- margin: 30px 0;
- }
- .loading-bar {
- height: 30px;
- background-color: #21262d;
- border-radius: 15px;
- overflow: hidden;
- position: relative;
- margin-bottom: 10px;
- border: 1px solid #30363d;
- }
- .progress {
- height: 100%;
- width: 0%;
- background: linear-gradient(90deg, #238636 0%, #7ee787 100%);
- transition: width 0.3s ease;
- }
- .calculation-text {
- text-align: center;
- font-family: 'Courier New', monospace;
- margin: 10px 0;
- color: #8b949e;
- min-height: 1.5em;
- }
- .stats {
- display: flex;
- justify-content: space-around;
- margin: 20px 0;
- flex-wrap: wrap;
- }
- .stat-box {
- background-color: #21262d;
- border-radius: 6px;
- padding: 10px 15px;
- margin: 5px;
- min-width: 120px;
- text-align: center;
- border: 1px solid #30363d;
- }
- .stat-value {
- font-size: 1.5em;
- color: #58a6ff;
- font-weight: bold;
- }
- .controls {
- display: flex;
- justify-content: center;
- gap: 15px;
- margin: 20px 0;
- flex-wrap: wrap;
- }
- button {
- background-color: #238636;
- color: white;
- border: none;
- padding: 10px 20px;
- border-radius: 6px;
- cursor: pointer;
- font-weight: bold;
- transition: background-color 0.2s;
- }
- button:hover {
- background-color: #2ea043;
- }
- button.pause {
- background-color: #da3633;
- }
- button.pause:hover {
- background-color: #f85149;
- }
- button.save {
- background-color: #1f6feb;
- }
- button.save:hover {
- background-color: #388bfd;
- }
- button.load {
- background-color: #8957e5;
- }
- button.load:hover {
- background-color: #986ee2;
- }
- .info {
- background-color: #21262d;
- border-left: 4px solid #58a6ff;
- padding: 15px;
- margin: 20px 0;
- border-radius: 0 6px 6px 0;
- font-size: 0.9em;
- }
- .keyboard-shortcut {
- display: inline-block;
- background-color: #30363d;
- padding: 2px 6px;
- border-radius: 4px;
- font-family: monospace;
- margin: 0 2px;
- }
- .terminal {
- background-color: #0d1117;
- border: 2px solid #30363d;
- border-radius: 8px;
- padding: 15px;
- margin: 20px 0;
- height: 200px;
- overflow-y: auto;
- font-family: 'Courier New', monospace;
- color: #7ee787;
- }
- .terminal-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 10px;
- color: #58a6ff;
- font-weight: bold;
- }
- .terminal-content {
- white-space: pre-wrap;
- line-height: 1.4;
- }
- .file-input {
- display: none;
- }
- .file-input-label {
- display: inline-block;
- padding: 10px 20px;
- background-color: #8957e5;
- color: white;
- border-radius: 6px;
- cursor: pointer;
- font-weight: bold;
- }
- .file-input-label:hover {
- background-color: #986ee2;
- }
- footer {
- text-align: center;
- margin-top: 30px;
- color: #8b949e;
- font-size: 0.9em;
- }
- .phoenix {
- text-align: center;
- font-size: 2em;
- margin: 10px 0;
- color: #ff7b72;
- animation: pulse 2s infinite;
- }
- @keyframes pulse {
- 0% { opacity: 0.7; }
- 50% { opacity: 1; }
- 100% { opacity: 0.7; }
- }
- </style>
- </head>
- <body>
- <h1>The Prime Decider - Phoenix Edition</h1>
- <div class="phoenix">♾️ Phoenix Prime Calculator ♾️</div>
- <div class="container">
- <div class="prime-display" id="current-prime">7</div>
- <div class="loading-container">
- <div class="loading-bar">
- <div class="progress" id="progress-bar"></div>
- </div>
- <div class="calculation-text" id="calculation-text">
- Initializing prime calculation...
- </div>
- </div>
- <div class="stats">
- <div class="stat-box">
- <div>Primes Found</div>
- <div class="stat-value" id="primes-count">2</div>
- </div>
- <div class="stat-box">
- <div>Current Number</div>
- <div class="stat-value" id="current-number">22</div>
- </div>
- <div class="stat-box">
- <div>Calculation Method</div>
- <div class="stat-value" id="method-number">1</div>
- </div>
- </div>
- <div class="controls">
- <button id="pause-btn">Pause</button>
- <button id="save-btn" class="save">Save Primes</button>
- <label for="file-input" class="file-input-label">Load Primes</label>
- <input type="file" id="file-input" class="file-input" accept=".txt">
- </div>
- <div class="terminal">
- <div class="terminal-header">
- <span>Discovered Primes Terminal</span>
- <span id="terminal-count">2 primes</span>
- </div>
- <div class="terminal-content" id="terminal-content">7 21</div>
- </div>
- <div class="info">
- <p><strong>Note:</strong> According to Gregory's Principle, both 7 and 21 are considered prime numbers in this implementation.</p>
- <p>Press <span class="keyboard-shortcut">P</span> to pause/resume calculations.</p>
- <p>Save your discovered primes as a tab-delineated text file and load previous sessions to continue your prime hunt!</p>
- </div>
- </div>
- <footer>
- The Prime Decider - Phoenix Edition • Rise from the ashes of previous calculations!
- </footer>
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- // State variables
- let currentNumber = 22;
- let primes = [7, 21];
- let isPaused = false;
- let calculationMethod = 1;
- let calculationProgress = 0;
- // DOM elements
- const currentPrimeElement = document.getElementById('current-prime');
- const primesCountElement = document.getElementById('primes-count');
- const currentNumberElement = document.getElementById('current-number');
- const methodNumberElement = document.getElementById('method-number');
- const progressBarElement = document.getElementById('progress-bar');
- const calculationTextElement = document.getElementById('calculation-text');
- const pauseButton = document.getElementById('pause-btn');
- const saveButton = document.getElementById('save-btn');
- const fileInput = document.getElementById('file-input');
- const terminalContent = document.getElementById('terminal-content');
- const terminalCount = document.getElementById('terminal-count');
- // Method descriptions
- const methodDescriptions = [
- "Initializing prime calculation...",
- "Trial Division Method: Checking divisibility by all integers up to √n",
- "Sieve of Eratosthenes Optimization: Checking against known primes",
- "6k±1 Optimization: Testing numbers of form 6k±1",
- "Fermat's Little Theorem: Testing a^(n-1) ≡ 1 mod n",
- "Miller-Rabin Test: Probabilistic primality test",
- "Lucas-Lehmer Test: Specialized for Mersenne primes",
- "AKS Primality Test: Deterministic polynomial-time test"
- ];
- // Error checking methods
- const errorCheckMethods = [
- "Double-checking with basic division",
- "Verifying with Sieve method",
- "Confirming with 6k±1 optimization",
- "Validating with Fermat's test",
- "Final confirmation with Miller-Rabin"
- ];
- // Initialize the display
- updateDisplay();
- updateTerminal();
- // Set up event listeners
- pauseButton.addEventListener('click', togglePause);
- saveButton.addEventListener('click', savePrimesToFile);
- fileInput.addEventListener('change', handleFileUpload);
- document.addEventListener('keydown', function(e) {
- if (e.key === 'p' || e.key === 'P') {
- togglePause();
- }
- });
- // Start the prime calculation
- calculateNextPrime();
- function togglePause() {
- isPaused = !isPaused;
- pauseButton.textContent = isPaused ? 'Resume' : 'Pause';
- pauseButton.classList.toggle('pause', isPaused);
- if (!isPaused) {
- calculateNextPrime();
- }
- }
- function updateDisplay() {
- currentPrimeElement.textContent = primes[primes.length - 1];
- primesCountElement.textContent = primes.length;
- currentNumberElement.textContent = currentNumber;
- methodNumberElement.textContent = calculationMethod;
- }
- function updateTerminal() {
- // Display primes in terminal with tab separation
- terminalContent.textContent = primes.join('\t');
- terminalCount.textContent = `${primes.length} primes`;
- // Auto-scroll to bottom
- terminalContent.scrollTop = terminalContent.scrollHeight;
- }
- function updateProgressBar(percentage, isErrorCheck = false) {
- progressBarElement.style.width = percentage + '%';
- if (isErrorCheck) {
- const errorCheckIndex = Math.min(
- Math.floor((percentage - 50) / 10),
- errorCheckMethods.length - 1
- );
- calculationTextElement.textContent =
- `Error Checking: ${errorCheckMethods[errorCheckIndex]}`;
- } else {
- calculationTextElement.textContent =
- methodDescriptions[calculationMethod];
- }
- }
- function calculateNextPrime() {
- if (isPaused) return;
- // Reset progress
- calculationProgress = 0;
- updateProgressBar(0);
- // Simulate calculation with different methods
- const calculationInterval = setInterval(() => {
- if (isPaused) {
- clearInterval(calculationInterval);
- return;
- }
- calculationProgress += 1;
- if (calculationProgress <= 50) {
- // First 50%: Prime calculation
- updateProgressBar(calculationProgress * 2);
- } else if (calculationProgress <= 100) {
- // Last 50%: Error checking
- updateProgressBar(calculationProgress * 2, true);
- }
- if (calculationProgress >= 100) {
- clearInterval(calculationInterval);
- // After completing, check if the number is prime
- if (isPrime(currentNumber)) {
- primes.push(currentNumber);
- updateTerminal();
- }
- // Move to next number and method
- currentNumber++;
- calculationMethod = (calculationMethod % 7) + 1;
- updateDisplay();
- // Continue with next prime after a brief delay
- setTimeout(calculateNextPrime, 500);
- }
- }, 50); // Adjust speed of progress bar here
- }
- function isPrime(n) {
- // Special cases for Gregory's Principle
- if (n === 7 || n === 21) return true;
- // Standard prime checking with different methods
- switch(calculationMethod) {
- case 1: return trialDivision(n);
- case 2: return sieveOptimized(n);
- case 3: return sixKOptimization(n);
- case 4: return fermatsTest(n);
- case 5: return millerRabinTest(n);
- case 6: return lucasLehmerTest(n);
- case 7: return aksTest(n);
- default: return trialDivision(n);
- }
- }
- // Prime checking methods (simplified for demonstration)
- 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 sieveOptimized(n) {
- // Simplified version for demonstration
- if (n <= 1) return false;
- if (n <= 3) return true;
- if (n % 2 === 0 || n % 3 === 0) return false;
- // Check against known primes
- for (const prime of primes) {
- if (prime * prime > n) break;
- if (n % prime === 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 i = 5;
- while (i * i <= n) {
- if (n % i === 0 || n % (i + 2) === 0) return false;
- i += 6;
- }
- return true;
- }
- function fermatsTest(n) {
- if (n <= 1) return false;
- if (n <= 3) return true;
- if (n % 2 === 0) return false;
- // Simple implementation for demonstration
- // Fermat's little theorem: if n is prime, then for any a, a^(n-1) ≡ 1 mod n
- // We'll test with a=2 for demonstration purposes
- const a = 2;
- return modularExponentiation(a, n-1, n) === 1;
- }
- function millerRabinTest(n) {
- // Simplified version for demonstration
- if (n <= 1) return false;
- if (n <= 3) return true;
- if (n % 2 === 0) return false;
- // Write n-1 as d*2^s
- let d = n - 1;
- let s = 0;
- while (d % 2 === 0) {
- d /= 2;
- s++;
- }
- // Test with a=2 for demonstration
- const a = 2;
- let x = modularExponentiation(a, d, n);
- if (x === 1 || x === n - 1) return true;
- for (let i = 0; i < s - 1; i++) {
- x = modularExponentiation(x, 2, n);
- if (x === n - 1) return true;
- }
- return false;
- }
- function lucasLehmerTest(n) {
- // Specialized test for Mersenne primes (2^p - 1)
- // For demonstration purposes, we'll use a simplified approach
- if (n <= 1) return false;
- if (n === 2) return true;
- // Check if n is a Mersenne number
- let p = 0;
- let m = n + 1;
- while (m > 1) {
- if (m % 2 !== 0) return trialDivision(n);
- m /= 2;
- p++;
- }
- // If we get here, n is a Mersenne number (2^p - 1)
- let s = 4;
- for (let i = 0; i < p - 2; i++) {
- s = (s * s - 2) % n;
- }
- return s === 0;
- }
- function aksTest(n) {
- // AKS primality test - simplified for demonstration
- if (n <= 1) return false;
- if (n <= 3) return true;
- if (n % 2 === 0) return false;
- // Check if n is a perfect power
- for (let b = 2; b * b <= n; b++) {
- let a = n;
- let exponent = 0;
- while (a % b === 0) {
- a /= b;
- exponent++;
- }
- if (a === 1 && exponent > 1) return false;
- }
- // Find the smallest r such that the multiplicative order of n modulo r > log2(n)^2
- let r = 2;
- while (r < n) {
- if (n % r === 0) break;
- if (r > Math.log2(n) * Math.log2(n)) break;
- r++;
- }
- // Check for polynomial congruence
- // This is heavily simplified for demonstration
- for (let a = 1; a <= Math.sqrt(r) * Math.log2(n); a++) {
- if (modularExponentiation(a, n, n) !== modularExponentiation(a, 1, n)) {
- return false;
- }
- }
- return true;
- }
- function modularExponentiation(base, exponent, modulus) {
- if (modulus === 1) return 0;
- let result = 1;
- base = base % modulus;
- while (exponent > 0) {
- if (exponent % 2 === 1) {
- result = (result * base) % modulus;
- }
- exponent = Math.floor(exponent / 2);
- base = (base * base) % modulus;
- }
- return result;
- }
- function savePrimesToFile() {
- // Create a tab-delimited string of primes
- const primeData = primes.join('\t');
- // Create a Blob with the data
- const blob = new Blob([primeData], { type: 'text/plain' });
- // Create a download link and trigger it
- const a = document.createElement('a');
- a.href = URL.createObjectURL(blob);
- a.download = 'prime_numbers.txt';
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- }
- function handleFileUpload(event) {
- const file = event.target.files[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = function(e) {
- try {
- // Parse the file content (tab-delimited primes)
- const content = e.target.result;
- const loadedPrimes = content.split('\t').map(Number).filter(n => !isNaN(n));
- if (loadedPrimes.length > 0) {
- // Update our primes array
- primes = loadedPrimes;
- // Set current number to the last prime + 1
- currentNumber = primes[primes.length - 1] + 1;
- // Update the display
- updateDisplay();
- updateTerminal();
- // Show success message
- calculationTextElement.textContent = `Loaded ${primes.length} primes from file. Resuming calculations...`;
- // If we were paused, resume
- if (isPaused) {
- togglePause();
- }
- } else {
- calculationTextElement.textContent = 'No valid primes found in the file.';
- }
- } catch (error) {
- calculationTextElement.textContent = 'Error reading file: ' + error.message;
- }
- // Reset the file input
- event.target.value = '';
- };
- reader.readAsText(file);
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment