Sieve of Eratosthenes

Try cutting and pasting this into the restricted Tcl interpreter, or return to the NArray page. set n 200 narray create sieve $n sieve status sieve map { # vector will contain 0 at [] if prime, 1 otherwise if ![] { inc = @0 + 2; for (i = @0 + inc; i < @#0; i += inc) { [i] = 1; } } } sieve map { # print out the results if ![] { printf("%4d ", @0 + 2); } post { printf("\n"); } }
Sam Shen, slshen@lbl.gov
Last modified: Tue Aug 9 16:37:31 1994