-
Notifications
You must be signed in to change notification settings - Fork 0
/
primes.html
109 lines (96 loc) · 2.53 KB
/
primes.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
99
100
101
102
103
104
105
106
107
108
109
<!-- saved from url=(0022)http://internet.e-mail -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Prime Numbers</title>
</head>
<body>
This program/site will calculate primes up to the entered number.
Using multiple threads, the application tests for primes using the "prime factors" method.
<form>
Enter a starting value: <input type="text" name="maxNum" value="10000"/>
<br>
<input type="button" name="go" onclick="kick()" value="start">
</form>
<table border="1" width="80%">
<tr>
<th>Thread 1</th>
<th>Thread 2</th>
<th>Thread 3</th>
<th>Thread 4</th>
</tr>
<tr><td bgcolor="lightgray" width="25%" valign="top"><div name="mainDiv0" id="mainDiv0"></div></td>
<td width="25%" valign="top"><div name="mainDiv1" id="mainDiv1"></div></td>
<td bgcolor="lightgray" width="25%" valign="top"><div name="mainDiv2" id="mainDiv2"></div></td>
<td width="25%" valign="top"><div name="mainDiv3" id="mainDiv3"></div></td>
</tr></table>
<SCRIPT>
function check(multiplier)
{
var factor=-1;
//window.status="Working...";
// Try each number up to the multiplier
for(i=1;i<multiplier;i++)
{
// If factor
if(multiplier / i == Math.round(multiplier / i) && i != 1 && i != multiplier)
{
factor=i;
break;
};
};
if(factor ==-1)
{
isprime(multiplier);
window.status="Prime Found!";
setTimeout('setStatusBackToWorking()', 1000);
return true
}
return false;
}
function isprime(number)
{
// var str = document.all['mainDiv'].innerHTML;
// alert(str)
document.all['mainDiv' + (Math.floor(Math.random()*4))].innerHTML += '<br>' + number;
currentNum++
setTimeout('restart()', 30);
}
var currentNum = 0;
var maxNum;
function kick()
{
maxNum = document.forms[0].maxNum.value;
restart();
}
function restart()
{
for(; currentNum < maxNum; currentNum++)
{
if(check(currentNum))
{
break;
}
}
if(currentNum == maxNum)
{
setTimeout('setStatusBackToDone()', 1200);
}
}
function setStatusBackToWorking()
{
window.status="Working....";
}
function setStatusBackToDone()
{
window.status="Done!";
}
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-550134-9', 'scienceontheweb.net');
ga('send', 'pageview');
</SCRIPT>
</body>
</html>