1 /* The Great Computer Language Shootout
2 http://shootout.alioth.debian.org
4 contributed by Ian Osgood */
6 Sequence pad
:= method(w
, s
:=self; while (s size
< w
, s
=" ".. s
) )
7 Number clearBit
:= method(b
, &(1 clone shiftLeft(b
) bitwiseComplement
) )
9 sieve
:= Object clone do(
10 flags
:= Sequence
clone do(
11 isSet
:= method(i
, at(i
/8) at(i
%8) != 0)
12 clear
:= method(i
, atPut(i
/8, at(i
/8) clearBit(i
%8) ) )
15 flags
setSize((n
/8) ceil
)
16 for (i
, 0, flags size
- 1, flags
atPut(i
, 255))
21 if (i
+i
< n
, for (j
, i
+i
, n
-1, i
, flags
clear(j
) ) )
24 writeln("Primes up to", n asString
pad(9), primes asString
pad(9))
28 n
:= args
at(1) asNumber
29 sieve
show(10000 shiftLeft(n
))
30 sieve
show(10000 shiftLeft(n
-1))
31 sieve
show(10000 shiftLeft(n
-2))