Debian Codegraph @

src/benchs/nsieve.neko

raw
1 /* The Computer Language Shootout
2 http://shootout.alioth.debian.org/
3
4 contributed by Nicolas Cannasse
5 */
6 fmt = function(i) {
7 var s = $string(i);
8 while( $ssize(s) < 8 )
9 s = " "+s;
10 return s;
11 }
12 nsieve = function(m) {
13 var a = $amake(m);
14 var count = 0;
15 var i = 2;
16 while( i < m ) {
17 if $not(a[i]) {
18 count += 1;
19 var j = (i << 1);
20 while( j < m ) {
21 if( $not(a[j]) ) a[j] = true;
22 j += i;
23 }
24 }
25 i += 1;
26 }
27 $print("Primes up to ",fmt(m)," ",fmt(count),"\n");
28 }
29
30 var n = $int($loader.args[0]);
31 if( n == null ) n = 2;
32 var i = 0;
33 while( i < 3 ) {
34 nsieve(10000 << (n - i));
35 i += 1;
36 }