document.addEventListener('DOMContentLoaded', function() { const numberInput = document.getElementById('numberInput'); const analyzeBtn = document.getElementById('analyzeBtn'); const clearBtn = document.getElementById('clearBtn'); const resultsContainer = document.getElementById('resultsContainer'); const patternExplanation = document.getElementById('patternExplanation'); const patternDetails = document.getElementById('patternDetails'); analyzeBtn.addEventListener('click', analyzeNumbers); clearBtn.addEventListener('click', clearAll); function analyzeNumbers() { const inputText = numberInput.value.trim(); if (!inputText) { showNotification('Please enter some numbers to analyze', 'error'); return; } const lines = inputText.split('\n').filter(line => line.trim() !== ''); const parsedData = lines.map(line => { const numbers = line.trim().split(/\s+/).map(num => parseInt(num, 10)); return { original: line.trim(), numbers, firstNum: numbers[0], secondNum: numbers[1], thirdNum: numbers[2] }; }); // Analyze patterns analyzePatterns(parsedData); } function analyzePatterns(data) { resultsContainer.innerHTML = ''; patternExplanation.classList.add('hidden'); // Check for common first numbers const firstNumbers = new Set(data.map(item => item.firstNum)); const hasCommonFirstNumber = firstNumbers.size === 1; // Calculate differences between numbers const secondNumbers = data.map(item => item.secondNum); const thirdNumbers = data.map(item => item.thirdNum); // Calculate differences and ratios const secondDiffs = []; const thirdDiffs = []; const secondThirdRatios = []; const firstThirdRatios = []; const secondToThirdDeltas = []; for (let i = 0; i < secondNumbers.length; i++) { if (i > 0) { secondDiffs.push(secondNumbers[i] - secondNumbers[i-1]); thirdDiffs.push(thirdNumbers[i] - thirdNumbers[i-1]); } secondThirdRatios.push((thirdNumbers[i] / secondNumbers[i]).toFixed(4)); firstThirdRatios.push((thirdNumbers[i] / data[i].firstNum).toFixed(4)); secondToThirdDeltas.push(thirdNumbers[i] - secondNumbers[i]); } // Look for mathematical relationships const possibleRelationships = []; const firstNum = data[0].firstNum; const avgSecondThirdRatio = (secondThirdRatios.reduce((a,b) => a + parseFloat(b), 0) / secondThirdRatios.length).toFixed(4); const avgFirstThirdRatio = (firstThirdRatios.reduce((a,b) => a + parseFloat(b), 0) / firstThirdRatios.length).toFixed(4); // Test if third number is a multiple of second number const ratioVariance = Math.max(...secondThirdRatios.map(parseFloat)) - Math.min(...secondThirdRatios.map(parseFloat)); if (ratioVariance < 0.01) { possibleRelationships.push(`Third number appears to be ~${avgSecondThirdRatio} × second number`); } // Test if third number is derived from first + second const firstPlusSecond = data.map(item => item.firstNum + item.secondNum); const firstPlusSecondToThirdRatio = data.map((item, i) => (item.thirdNum / firstPlusSecond[i]).toFixed(4)); const avgFirstPlusSecondRatio = (firstPlusSecondToThirdRatio.reduce((a,b) => a + parseFloat(b), 0) / firstPlusSecondToThirdRatio.length).toFixed(4); if (firstPlusSecondToThirdRatio.every(r => Math.abs(parseFloat(r) - parseFloat(avgFirstPlusSecondRatio)) < 0.001)) { possibleRelationships.push(`Third number appears to be ~${avgFirstPlusSecondRatio} × (first + second number)`); } // Display results displayResults(data, { hasCommonFirstNumber, commonFirstNumber: hasCommonFirstNumber ? data[0].firstNum : null, secondDiffs, thirdDiffs, secondNumbers, thirdNumbers, secondThirdRatios, firstThirdRatios, secondToThirdDeltas, possibleRelationships, firstPlusSecondToThirdRatio, avgSecondThirdRatio, avgFirstThirdRatio, avgFirstPlusSecondRatio }); } function displayResults(data, analysis) { // Display the raw data in a table let tableHTML = `
`; data.forEach((item, index) => { tableHTML += ` `; }); tableHTML += `
Sequence First Second Third
${item.original} ${item.firstNum} ${item.secondNum} ${item.thirdNum}
`; resultsContainer.innerHTML = tableHTML; // Now analyze and display the pattern analyzeAndDisplayPattern(analysis); } function analyzeAndDisplayPattern(analysis) { patternExplanation.classList.remove('hidden'); let patternHTML = `

First Number Analysis

${analysis.hasCommonFirstNumber ? `All sequences share the same first number: ${analysis.commonFirstNumber}` : `The first numbers vary across sequences`}

Second Number Analysis

Differences between consecutive second numbers:

`; analysis.secondDiffs.forEach((diff, index) => { const diffClass = diff > 0 ? 'bg-blue-900 text-blue-200' : diff < 0 ? 'bg-blue-800 text-blue-200' : 'bg-gray-700 text-gray-300'; patternHTML += `${diff >= 0 ? '+' : ''}${diff}`; }); patternHTML += `

Third Number Analysis

Differences between consecutive third numbers:

`; analysis.thirdDiffs.forEach((diff, index) => { const diffClass = diff > 0 ? 'bg-green-900 text-green-200' : diff < 0 ? 'bg-green-800 text-green-200' : 'bg-gray-700 text-gray-300'; patternHTML += `${diff >= 0 ? '+' : ''}${diff}`; }); patternHTML += `

Mathematical Relationships

Second → Third Ratios

`; analysis.secondThirdRatios.forEach((ratio, index) => { patternHTML += `${ratio}`; }); patternHTML += `

Average ratio: ${analysis.avgSecondThirdRatio}

First + Second → Third Ratios

`; analysis.firstPlusSecondToThirdRatio.forEach((ratio, index) => { patternHTML += `${ratio}`; }); patternHTML += `

Average ratio: ${analysis.avgFirstPlusSecondRatio}

Potential Pattern

Possible relationships:

Key Observations:

`; patternDetails.innerHTML = patternHTML; feather.replace(); } function clearAll() { numberInput.value = ''; resultsContainer.innerHTML = `

Enter numbers above to see the magic happen!

`; patternExplanation.classList.add('hidden'); feather.replace(); } function showNotification(message, type = 'success') { const notification = document.createElement('div'); notification.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-lg text-white ${ type === 'error' ? 'bg-red-600' : 'bg-green-600' }`; notification.textContent = message; document.body.appendChild(notification); setTimeout(() => { notification.classList.add('opacity-0', 'transition-opacity', 'duration-300'); setTimeout(() => notification.remove(), 300); }, 3000); } });