-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
93 lines (82 loc) · 3.39 KB
/
index.html
File metadata and controls
93 lines (82 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pi Number Search</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 20px;
}
input, button {
padding: 8px;
margin: 5px;
}
#result {
margin-top: 20px;
word-wrap: break-word;
}
.highlight {
background-color: yellow;
}
</style>
</head>
<body>
<h1>Search Numbers in Pi</h1>
<p>Enter a number sequence to find its position in the first 1 million digits of Pi:</p>
<input type="text" id="searchInput" placeholder="Enter numbers" disabled>
<button onclick="searchPi()" disabled id="searchButton">Search</button>
<div id="result">Loading Pi digits...</div>
<script>
let pi = '';
// Load Pi from file
async function loadPi() {
try {
const response = await fetch('pi.txt');
if (!response.ok) throw new Error('File not found');
pi = await response.text();
document.getElementById('searchInput').disabled = false;
document.getElementById('searchButton').disabled = false;
document.getElementById('result').innerHTML = 'Ready! Enter a number sequence to search.';
} catch (error) {
document.getElementById('result').innerHTML = `Error loading Pi: ${error.message}. Please ensure pi_100k.txt is in the same directory.`;
}
}
function searchPi() {
const searchTerm = document.getElementById('searchInput').value.replace(/\s/g, '');
const resultDiv = document.getElementById('result');
if (!searchTerm || !/^\d+$/.test(searchTerm)) {
resultDiv.innerHTML = "Please enter a valid number sequence.";
return;
}
const piNoSpaces = pi.replace(/\s/g, '');
const position = piNoSpaces.indexOf(searchTerm);
if (position === -1) {
resultDiv.innerHTML = `Sequence "${searchTerm}" not found in the first 100,000 digits of Pi.`;
} else {
// Show snippet around match
const snippetStart = Math.max(0, position - 50);
const snippetEnd = Math.min(piNoSpaces.length, position + searchTerm.length + 50);
const before = piNoSpaces.substring(snippetStart, position);
const match = piNoSpaces.substring(position, position + searchTerm.length);
const after = piNoSpaces.substring(position + searchTerm.length, snippetEnd);
resultDiv.innerHTML = `
Found "${searchTerm}" at position ${position + 1} (counting from 1 after decimal point):<br>
...${before}<span class="highlight">${match}</span>${after}...
`;
}
}
// Allow Enter key to trigger search
document.getElementById('searchInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
searchPi();
}
});
// Start loading Pi when page loads
loadPi();
</script>
</body>
</html>