-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.html
98 lines (80 loc) · 2.62 KB
/
list.html
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
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<title>Primes</title>
<link rel="shortcut icon" href="assets/favicon.ico">
</head>
<body>
<script type="text/javascript">
jbDebugMode = true; // Enable debugging for JBrix! (Easy 8) )
</script>
<script src="https://rawgit.com/YSCHGroup/JBrix/master/functions/jb-getUrlVariables.js"></script> <!-- Import JBrix getUrlVariables module -->
<script type="text/javascript">
function lastElementIn(arr) {
return arr[arr.length-1];
}
function formatNumber(str) {
return String(str).replace(new RegExp(" ", "g"), "").split(".").join("").replace(new RegExp(",", "g"), "");
}
function calcPrimes() {
from = +formatNumber(from);
to = +formatNumber(to);
if (typeof raw == "undefined") {raw = false}
else if (raw == "false") {raw = false}
else if (raw == "true") {raw = true}
if (typeof showIndex == "undefined") {showIndex = false}
else if (showIndex == "false") {showIndex = false}
else if (showIndex == "true") {showIndex = true}
if (!(isNaN(from) || isNaN(to))) {
var numbers = [2]
var pIndex = 0;
if (!raw) {
if (showIndex) {
document.write("Calculating prime numbers between " + from + " and " + to + "<br><br><em>[Index] : [Prime]</em><br><br>");
}else {
document.write("Calculating prime numbers between " + from + " and " + to + "<br><br>");
}
}
console.log("Raw From: " + from + "\nRaw To: " + to)
if (from <= lastElementIn(numbers)) {
if (showIndex) { document.write(pIndex + " : <b>" + lastElementIn(numbers) + "</b><br>"); }
else { document.write(lastElementIn(numbers) + "<br>"); }
pIndex++;
from = lastElementIn(numbers);
}
while(from > lastElementIn(numbers)) {
var largestNum = lastElementIn(numbers);
numbers.push(largestNum + 1);
}
try {
var Dividable;
for (var n = from; n < to; n++) {
Dividable = false;
for (var i = numbers.length - 1; i >= 0; i--) {
if (n % numbers[i] == 0) {
Dividable = true;
break;
}
}
if (!Dividable) {
if (showIndex) { document.write(pIndex + " : <b>" + n + "</b><br>"); }
else { document.write(n + "<br>"); }
pIndex++;
}
numbers.push(n);
}
}
catch(e) {
console.log(e);
}
if (!raw) { document.write("<br>Found a totla of " + pIndex + " primes!"); }
console.log(numbers);
}
}
// Run it.
calcPrimes();
// Add a return to menu button
if (!raw) { document.write('<br><button onclick="location.href=\'index.html\'" style="padding: 0 20px;" id="returnBtn">Back</button>'); }
</script>
</body>
</html>