/* File: prime.nrx */ /* prime number generation in NetRexx */ upto = 1000 tbl = sieve(upto) cnt = tbl.print say "Number of primes in 2.." upto " is " cnt |
/* File: sieve.nrx */ class sieve properties public table = boolean[] properties private upto pos method sieve(n) upto = n table = boolean[upto + 1] loop i = 2 to upto table[i] = 1 end loop i = 2 to upto if table[i] then loop j = i + i to upto by i table[j] = 0 end end method first returns int pos = 1 return this.next method next returns int loop pos = pos + 1 to upto if table[pos] then return pos end return -1 method print returns int cnt = 0 p = this.first loop while p > 0 say p "\-" cnt = cnt + 1 p = this.next end say return cnt |