XTaylorSpenceX

Phoenix Prime Calculator v1.0DA

Sep 18th, 2025
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 23.53 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.         body {
  9.             font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  10.             max-width: 1000px;
  11.             margin: 0 auto;
  12.             padding: 20px;
  13.             background-color: #0d1117;
  14.             color: #c9d1d9;
  15.             line-height: 1.6;
  16.         }
  17.         h1 {
  18.             color: #58a6ff;
  19.             text-align: center;
  20.             border-bottom: 2px solid #30363d;
  21.             padding-bottom: 10px;
  22.             margin-bottom: 20px;
  23.         }
  24.         .container {
  25.             background-color: #161b22;
  26.             border-radius: 8px;
  27.             padding: 20px;
  28.             box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  29.             margin-bottom: 20px;
  30.         }
  31.         .prime-display {
  32.             font-size: 2.5em;
  33.             text-align: center;
  34.             margin: 20px 0;
  35.             color: #7ee787;
  36.             font-weight: bold;
  37.         }
  38.         .loading-container {
  39.             margin: 30px 0;
  40.         }
  41.         .loading-bar {
  42.             height: 30px;
  43.             background-color: #21262d;
  44.             border-radius: 15px;
  45.             overflow: hidden;
  46.             position: relative;
  47.             margin-bottom: 10px;
  48.             border: 1px solid #30363d;
  49.         }
  50.         .progress {
  51.             height: 100%;
  52.             width: 0%;
  53.             background: linear-gradient(90deg, #238636 0%, #7ee787 100%);
  54.             transition: width 0.3s ease;
  55.         }
  56.         .calculation-text {
  57.             text-align: center;
  58.             font-family: 'Courier New', monospace;
  59.             margin: 10px 0;
  60.             color: #8b949e;
  61.             min-height: 1.5em;
  62.         }
  63.         .stats {
  64.             display: flex;
  65.             justify-content: space-around;
  66.             margin: 20px 0;
  67.             flex-wrap: wrap;
  68.         }
  69.         .stat-box {
  70.             background-color: #21262d;
  71.             border-radius: 6px;
  72.             padding: 10px 15px;
  73.             margin: 5px;
  74.             min-width: 120px;
  75.             text-align: center;
  76.             border: 1px solid #30363d;
  77.         }
  78.         .stat-value {
  79.             font-size: 1.5em;
  80.             color: #58a6ff;
  81.             font-weight: bold;
  82.         }
  83.         .controls {
  84.             display: flex;
  85.             justify-content: center;
  86.             gap: 15px;
  87.             margin: 20px 0;
  88.             flex-wrap: wrap;
  89.         }
  90.         button {
  91.             background-color: #238636;
  92.             color: white;
  93.             border: none;
  94.             padding: 10px 20px;
  95.             border-radius: 6px;
  96.             cursor: pointer;
  97.             font-weight: bold;
  98.             transition: background-color 0.2s;
  99.         }
  100.         button:hover {
  101.             background-color: #2ea043;
  102.         }
  103.         button.pause {
  104.             background-color: #da3633;
  105.         }
  106.         button.pause:hover {
  107.             background-color: #f85149;
  108.         }
  109.         button.save {
  110.             background-color: #1f6feb;
  111.         }
  112.         button.save:hover {
  113.             background-color: #388bfd;
  114.         }
  115.         button.load {
  116.             background-color: #8957e5;
  117.         }
  118.         button.load:hover {
  119.             background-color: #986ee2;
  120.         }
  121.         .info {
  122.             background-color: #21262d;
  123.             border-left: 4px solid #58a6ff;
  124.             padding: 15px;
  125.             margin: 20px 0;
  126.             border-radius: 0 6px 6px 0;
  127.             font-size: 0.9em;
  128.         }
  129.         .keyboard-shortcut {
  130.             display: inline-block;
  131.             background-color: #30363d;
  132.             padding: 2px 6px;
  133.             border-radius: 4px;
  134.             font-family: monospace;
  135.             margin: 0 2px;
  136.         }
  137.         .terminal {
  138.             background-color: #0d1117;
  139.             border: 2px solid #30363d;
  140.             border-radius: 8px;
  141.             padding: 15px;
  142.             margin: 20px 0;
  143.             height: 200px;
  144.             overflow-y: auto;
  145.             font-family: 'Courier New', monospace;
  146.             color: #7ee787;
  147.         }
  148.         .terminal-header {
  149.             display: flex;
  150.             justify-content: space-between;
  151.             align-items: center;
  152.             margin-bottom: 10px;
  153.             color: #58a6ff;
  154.             font-weight: bold;
  155.         }
  156.         .terminal-content {
  157.             white-space: pre-wrap;
  158.             line-height: 1.4;
  159.         }
  160.         .file-input {
  161.             display: none;
  162.         }
  163.         .file-input-label {
  164.             display: inline-block;
  165.             padding: 10px 20px;
  166.             background-color: #8957e5;
  167.             color: white;
  168.             border-radius: 6px;
  169.             cursor: pointer;
  170.             font-weight: bold;
  171.         }
  172.         .file-input-label:hover {
  173.             background-color: #986ee2;
  174.         }
  175.         footer {
  176.             text-align: center;
  177.             margin-top: 30px;
  178.             color: #8b949e;
  179.             font-size: 0.9em;
  180.         }
  181.         .phoenix {
  182.             text-align: center;
  183.             font-size: 2em;
  184.             margin: 10px 0;
  185.             color: #ff7b72;
  186.             animation: pulse 2s infinite;
  187.         }
  188.         @keyframes pulse {
  189.             0% { opacity: 0.7; }
  190.             50% { opacity: 1; }
  191.             100% { opacity: 0.7; }
  192.         }
  193.     </style>
  194. </head>
  195. <body>
  196.     <h1>The Prime Decider - Phoenix Edition</h1>
  197.     <div class="phoenix">♾️ Phoenix Prime Calculator ♾️</div>
  198.    
  199.     <div class="container">
  200.         <div class="prime-display" id="current-prime">7</div>
  201.        
  202.         <div class="loading-container">
  203.             <div class="loading-bar">
  204.                 <div class="progress" id="progress-bar"></div>
  205.             </div>
  206.             <div class="calculation-text" id="calculation-text">
  207.                 Initializing prime calculation...
  208.             </div>
  209.         </div>
  210.        
  211.         <div class="stats">
  212.             <div class="stat-box">
  213.                 <div>Primes Found</div>
  214.                 <div class="stat-value" id="primes-count">2</div>
  215.             </div>
  216.             <div class="stat-box">
  217.                 <div>Current Number</div>
  218.                 <div class="stat-value" id="current-number">22</div>
  219.             </div>
  220.             <div class="stat-box">
  221.                 <div>Calculation Method</div>
  222.                 <div class="stat-value" id="method-number">1</div>
  223.             </div>
  224.         </div>
  225.        
  226.         <div class="controls">
  227.             <button id="pause-btn">Pause</button>
  228.             <button id="save-btn" class="save">Save Primes</button>
  229.             <label for="file-input" class="file-input-label">Load Primes</label>
  230.             <input type="file" id="file-input" class="file-input" accept=".txt">
  231.         </div>
  232.        
  233.         <div class="terminal">
  234.             <div class="terminal-header">
  235.                 <span>Discovered Primes Terminal</span>
  236.                 <span id="terminal-count">2 primes</span>
  237.             </div>
  238.             <div class="terminal-content" id="terminal-content">7    21</div>
  239.         </div>
  240.        
  241.         <div class="info">
  242.             <p><strong>Note:</strong> According to Gregory's Principle, both 7 and 21 are considered prime numbers in this implementation.</p>
  243.             <p>Press <span class="keyboard-shortcut">P</span> to pause/resume calculations.</p>
  244.             <p>Save your discovered primes as a tab-delineated text file and load previous sessions to continue your prime hunt!</p>
  245.         </div>
  246.     </div>
  247.    
  248.     <footer>
  249.         The Prime Decider - Phoenix Edition &bull; Rise from the ashes of previous calculations!
  250.     </footer>
  251.  
  252.     <script>
  253.         document.addEventListener('DOMContentLoaded', function() {
  254.             // State variables
  255.             let currentNumber = 22;
  256.             let primes = [7, 21];
  257.             let isPaused = false;
  258.             let calculationMethod = 1;
  259.             let calculationProgress = 0;
  260.            
  261.             // DOM elements
  262.             const currentPrimeElement = document.getElementById('current-prime');
  263.             const primesCountElement = document.getElementById('primes-count');
  264.             const currentNumberElement = document.getElementById('current-number');
  265.             const methodNumberElement = document.getElementById('method-number');
  266.             const progressBarElement = document.getElementById('progress-bar');
  267.             const calculationTextElement = document.getElementById('calculation-text');
  268.             const pauseButton = document.getElementById('pause-btn');
  269.             const saveButton = document.getElementById('save-btn');
  270.             const fileInput = document.getElementById('file-input');
  271.             const terminalContent = document.getElementById('terminal-content');
  272.             const terminalCount = document.getElementById('terminal-count');
  273.            
  274.             // Method descriptions
  275.             const methodDescriptions = [
  276.                 "Initializing prime calculation...",
  277.                 "Trial Division Method: Checking divisibility by all integers up to √n",
  278.                 "Sieve of Eratosthenes Optimization: Checking against known primes",
  279.                 "6k±1 Optimization: Testing numbers of form 6k±1",
  280.                 "Fermat's Little Theorem: Testing a^(n-1) ≡ 1 mod n",
  281.                 "Miller-Rabin Test: Probabilistic primality test",
  282.                 "Lucas-Lehmer Test: Specialized for Mersenne primes",
  283.                 "AKS Primality Test: Deterministic polynomial-time test"
  284.             ];
  285.            
  286.             // Error checking methods
  287.             const errorCheckMethods = [
  288.                 "Double-checking with basic division",
  289.                 "Verifying with Sieve method",
  290.                 "Confirming with 6k±1 optimization",
  291.                 "Validating with Fermat's test",
  292.                 "Final confirmation with Miller-Rabin"
  293.             ];
  294.            
  295.             // Initialize the display
  296.             updateDisplay();
  297.             updateTerminal();
  298.            
  299.             // Set up event listeners
  300.             pauseButton.addEventListener('click', togglePause);
  301.             saveButton.addEventListener('click', savePrimesToFile);
  302.             fileInput.addEventListener('change', handleFileUpload);
  303.             document.addEventListener('keydown', function(e) {
  304.                 if (e.key === 'p' || e.key === 'P') {
  305.                     togglePause();
  306.                 }
  307.             });
  308.            
  309.             // Start the prime calculation
  310.             calculateNextPrime();
  311.            
  312.             function togglePause() {
  313.                 isPaused = !isPaused;
  314.                 pauseButton.textContent = isPaused ? 'Resume' : 'Pause';
  315.                 pauseButton.classList.toggle('pause', isPaused);
  316.                
  317.                 if (!isPaused) {
  318.                     calculateNextPrime();
  319.                 }
  320.             }
  321.            
  322.             function updateDisplay() {
  323.                 currentPrimeElement.textContent = primes[primes.length - 1];
  324.                 primesCountElement.textContent = primes.length;
  325.                 currentNumberElement.textContent = currentNumber;
  326.                 methodNumberElement.textContent = calculationMethod;
  327.             }
  328.            
  329.             function updateTerminal() {
  330.                 // Display primes in terminal with tab separation
  331.                 terminalContent.textContent = primes.join('\t');
  332.                 terminalCount.textContent = `${primes.length} primes`;
  333.                
  334.                 // Auto-scroll to bottom
  335.                 terminalContent.scrollTop = terminalContent.scrollHeight;
  336.             }
  337.            
  338.             function updateProgressBar(percentage, isErrorCheck = false) {
  339.                 progressBarElement.style.width = percentage + '%';
  340.                
  341.                 if (isErrorCheck) {
  342.                     const errorCheckIndex = Math.min(
  343.                         Math.floor((percentage - 50) / 10),
  344.                         errorCheckMethods.length - 1
  345.                     );
  346.                     calculationTextElement.textContent =
  347.                         `Error Checking: ${errorCheckMethods[errorCheckIndex]}`;
  348.                 } else {
  349.                     calculationTextElement.textContent =
  350.                         methodDescriptions[calculationMethod];
  351.                 }
  352.             }
  353.            
  354.             function calculateNextPrime() {
  355.                 if (isPaused) return;
  356.                
  357.                 // Reset progress
  358.                 calculationProgress = 0;
  359.                 updateProgressBar(0);
  360.                
  361.                 // Simulate calculation with different methods
  362.                 const calculationInterval = setInterval(() => {
  363.                     if (isPaused) {
  364.                         clearInterval(calculationInterval);
  365.                         return;
  366.                     }
  367.                    
  368.                     calculationProgress += 1;
  369.                    
  370.                     if (calculationProgress <= 50) {
  371.                        // First 50%: Prime calculation
  372.                        updateProgressBar(calculationProgress * 2);
  373.                    } else if (calculationProgress <= 100) {
  374.                        // Last 50%: Error checking
  375.                        updateProgressBar(calculationProgress * 2, true);
  376.                    }
  377.                    
  378.                    if (calculationProgress >= 100) {
  379.                         clearInterval(calculationInterval);
  380.                        
  381.                         // After completing, check if the number is prime
  382.                         if (isPrime(currentNumber)) {
  383.                             primes.push(currentNumber);
  384.                             updateTerminal();
  385.                         }
  386.                        
  387.                         // Move to next number and method
  388.                         currentNumber++;
  389.                         calculationMethod = (calculationMethod % 7) + 1;
  390.                        
  391.                         updateDisplay();
  392.                        
  393.                         // Continue with next prime after a brief delay
  394.                         setTimeout(calculateNextPrime, 500);
  395.                     }
  396.                 }, 50); // Adjust speed of progress bar here
  397.             }
  398.            
  399.             function isPrime(n) {
  400.                 // Special cases for Gregory's Principle
  401.                 if (n === 7 || n === 21) return true;
  402.                
  403.                 // Standard prime checking with different methods
  404.                 switch(calculationMethod) {
  405.                     case 1: return trialDivision(n);
  406.                     case 2: return sieveOptimized(n);
  407.                     case 3: return sixKOptimization(n);
  408.                     case 4: return fermatsTest(n);
  409.                     case 5: return millerRabinTest(n);
  410.                     case 6: return lucasLehmerTest(n);
  411.                     case 7: return aksTest(n);
  412.                     default: return trialDivision(n);
  413.                 }
  414.             }
  415.            
  416.             // Prime checking methods (simplified for demonstration)
  417.             function trialDivision(n) {
  418.                 if (n <= 1) return false;
  419.                if (n <= 3) return true;
  420.                if (n % 2 === 0 || n % 3 === 0) return false;
  421.                
  422.                for (let i = 5; i * i <= n; i += 6) {
  423.                    if (n % i === 0 || n % (i + 2) === 0) return false;
  424.                }
  425.                return true;
  426.            }
  427.            
  428.            function sieveOptimized(n) {
  429.                // Simplified version for demonstration
  430.                if (n <= 1) return false;
  431.                if (n <= 3) return true;
  432.                if (n % 2 === 0 || n % 3 === 0) return false;
  433.                
  434.                // Check against known primes
  435.                for (const prime of primes) {
  436.                    if (prime * prime > n) break;
  437.                     if (n % prime === 0) return false;
  438.                 }
  439.                 return true;
  440.             }
  441.            
  442.             function sixKOptimization(n) {
  443.                 if (n <= 1) return false;
  444.                if (n <= 3) return true;
  445.                if (n % 2 === 0 || n % 3 === 0) return false;
  446.                
  447.                let i = 5;
  448.                while (i * i <= n) {
  449.                    if (n % i === 0 || n % (i + 2) === 0) return false;
  450.                    i += 6;
  451.                }
  452.                return true;
  453.            }
  454.            
  455.            function fermatsTest(n) {
  456.                if (n <= 1) return false;
  457.                if (n <= 3) return true;
  458.                if (n % 2 === 0) return false;
  459.                
  460.                // Simple implementation for demonstration
  461.                // Fermat's little theorem: if n is prime, then for any a, a^(n-1) ≡ 1 mod n
  462.                // We'll test with a=2 for demonstration purposes
  463.                const a = 2;
  464.                return modularExponentiation(a, n-1, n) === 1;
  465.            }
  466.            
  467.            function millerRabinTest(n) {
  468.                // Simplified version for demonstration
  469.                if (n <= 1) return false;
  470.                if (n <= 3) return true;
  471.                if (n % 2 === 0) return false;
  472.                
  473.                // Write n-1 as d*2^s
  474.                let d = n - 1;
  475.                let s = 0;
  476.                while (d % 2 === 0) {
  477.                    d /= 2;
  478.                    s++;
  479.                }
  480.                
  481.                // Test with a=2 for demonstration
  482.                const a = 2;
  483.                let x = modularExponentiation(a, d, n);
  484.                
  485.                if (x === 1 || x === n - 1) return true;
  486.                
  487.                for (let i = 0; i < s - 1; i++) {
  488.                    x = modularExponentiation(x, 2, n);
  489.                    if (x === n - 1) return true;
  490.                }
  491.                
  492.                return false;
  493.            }
  494.            
  495.            function lucasLehmerTest(n) {
  496.                // Specialized test for Mersenne primes (2^p - 1)
  497.                // For demonstration purposes, we'll use a simplified approach
  498.                if (n <= 1) return false;
  499.                if (n === 2) return true;
  500.                
  501.                // Check if n is a Mersenne number
  502.                let p = 0;
  503.                let m = n + 1;
  504.                while (m > 1) {
  505.                     if (m % 2 !== 0) return trialDivision(n);
  506.                     m /= 2;
  507.                     p++;
  508.                 }
  509.                
  510.                 // If we get here, n is a Mersenne number (2^p - 1)
  511.                 let s = 4;
  512.                 for (let i = 0; i < p - 2; i++) {
  513.                    s = (s * s - 2) % n;
  514.                }
  515.                return s === 0;
  516.            }
  517.            
  518.            function aksTest(n) {
  519.                // AKS primality test - simplified for demonstration
  520.                if (n <= 1) return false;
  521.                if (n <= 3) return true;
  522.                if (n % 2 === 0) return false;
  523.                
  524.                // Check if n is a perfect power
  525.                for (let b = 2; b * b <= n; b++) {
  526.                    let a = n;
  527.                    let exponent = 0;
  528.                    while (a % b === 0) {
  529.                        a /= b;
  530.                        exponent++;
  531.                    }
  532.                    if (a === 1 && exponent > 1) return false;
  533.                 }
  534.                
  535.                 // Find the smallest r such that the multiplicative order of n modulo r > log2(n)^2
  536.                 let r = 2;
  537.                 while (r < n) {
  538.                    if (n % r === 0) break;
  539.                    if (r > Math.log2(n) * Math.log2(n)) break;
  540.                     r++;
  541.                 }
  542.                
  543.                 // Check for polynomial congruence
  544.                 // This is heavily simplified for demonstration
  545.                 for (let a = 1; a <= Math.sqrt(r) * Math.log2(n); a++) {
  546.                    if (modularExponentiation(a, n, n) !== modularExponentiation(a, 1, n)) {
  547.                        return false;
  548.                    }
  549.                }
  550.                
  551.                return true;
  552.            }
  553.            
  554.            function modularExponentiation(base, exponent, modulus) {
  555.                if (modulus === 1) return 0;
  556.                
  557.                let result = 1;
  558.                base = base % modulus;
  559.                
  560.                while (exponent > 0) {
  561.                     if (exponent % 2 === 1) {
  562.                         result = (result * base) % modulus;
  563.                     }
  564.                     exponent = Math.floor(exponent / 2);
  565.                     base = (base * base) % modulus;
  566.                 }
  567.                
  568.                 return result;
  569.             }
  570.            
  571.             function savePrimesToFile() {
  572.                 // Create a tab-delimited string of primes
  573.                 const primeData = primes.join('\t');
  574.                
  575.                 // Create a Blob with the data
  576.                 const blob = new Blob([primeData], { type: 'text/plain' });
  577.                
  578.                 // Create a download link and trigger it
  579.                 const a = document.createElement('a');
  580.                 a.href = URL.createObjectURL(blob);
  581.                 a.download = 'prime_numbers.txt';
  582.                 document.body.appendChild(a);
  583.                 a.click();
  584.                 document.body.removeChild(a);
  585.             }
  586.            
  587.             function handleFileUpload(event) {
  588.                 const file = event.target.files[0];
  589.                 if (!file) return;
  590.                
  591.                 const reader = new FileReader();
  592.                 reader.onload = function(e) {
  593.                     try {
  594.                         // Parse the file content (tab-delimited primes)
  595.                         const content = e.target.result;
  596.                         const loadedPrimes = content.split('\t').map(Number).filter(n => !isNaN(n));
  597.                        
  598.                         if (loadedPrimes.length > 0) {
  599.                             // Update our primes array
  600.                             primes = loadedPrimes;
  601.                            
  602.                             // Set current number to the last prime + 1
  603.                             currentNumber = primes[primes.length - 1] + 1;
  604.                            
  605.                             // Update the display
  606.                             updateDisplay();
  607.                             updateTerminal();
  608.                            
  609.                             // Show success message
  610.                             calculationTextElement.textContent = `Loaded ${primes.length} primes from file. Resuming calculations...`;
  611.                            
  612.                             // If we were paused, resume
  613.                             if (isPaused) {
  614.                                 togglePause();
  615.                             }
  616.                         } else {
  617.                             calculationTextElement.textContent = 'No valid primes found in the file.';
  618.                         }
  619.                     } catch (error) {
  620.                         calculationTextElement.textContent = 'Error reading file: ' + error.message;
  621.                     }
  622.                    
  623.                     // Reset the file input
  624.                     event.target.value = '';
  625.                 };
  626.                 reader.readAsText(file);
  627.             }
  628.         });
  629.     </script>
  630. </body>
  631. </html>
  632.  
Advertisement
Add Comment
Please, Sign In to add comment