58 lines
1.4 KiB
HTML
58 lines
1.4 KiB
HTML
<html>
|
|
<head>
|
|
<link rel=stylesheet type="text/css" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<H2>
|
|
JavaScript samples. Sieve of Eratosthenes.
|
|
</H2>
|
|
<hr>
|
|
|
|
|
|
<blockquote>
|
|
<pre>
|
|
<font color="blue"><b>println</b></font>(<font color="Red">"Eratosthenes Sieve prime number calculation"</font>);
|
|
|
|
size = 8190;
|
|
sizepl = 8191;
|
|
|
|
<font color="blue"><b>var</b></font> flags = <font color="blue"><b>new</b></font> Array(sizepl);
|
|
|
|
<font color="blue"><b>var</b></font> i, prime, k, count, iter;
|
|
|
|
alert(<font color="Red">"10 iterations"</font>);
|
|
starttime = <font color="blue"><b>new</b></font> Date();
|
|
<font color="blue"><b>for</b></font> (iter = 1; iter <= 10; iter++)
|
|
{ count = 0;
|
|
<font color="blue"><b>for</b></font> (i = 0; i <= size; i++)
|
|
flags[i] = <font color="blue"><b>true</b></font>;
|
|
<font color="blue"><b>for</b></font> (i = 0; i <= size; i++)
|
|
{ if (flags[i])
|
|
{ prime = i + i + 3;
|
|
k = i + prime;
|
|
<font color="blue"><b>while</b></font> (k <= size)
|
|
{
|
|
flags[k] = <font color="blue"><b>false</b></font>;
|
|
k += prime;
|
|
}
|
|
count += 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
elapsedtime = <font color="blue"><b>new</b></font> Date() - starttime;
|
|
<font color="blue"><b>println</b></font>(count + <font color="Red">" primes"</font>);
|
|
<font color="blue"><b>println</b></font>(<font color="Red">"elapsed time = "</font> + elapsedtime);
|
|
</pre>
|
|
</blockquote>
|
|
|
|
|
|
<p>
|
|
<HR>
|
|
<font size = 1 color ="gray">
|
|
Copyright © 2006-2009
|
|
VIRT Laboratory. All rights reserved.
|
|
</font>
|
|
</body>
|
|
</html>
|