Sieve of Eratosthenes: Difference between revisions

Content deleted Content added
Rahul (talk | contribs)
Line 484:
 
As Melissa O'Neill demonstrates in [http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf The Genuine Sieve of Eratosthenes], this version is not better than trial division. She also presents an actual purely functional version that uses priority queues, and is much easier to combine with [http://http://en.wikipedia.org/wiki/Wheel_factorization wheels] (pre-calculated sieves for small primes) than the imperative version. Even combined with a simple wheel, the speed of this version is similar to the imperative version.
 
=={{header|Icon}}==
[http://www.tools-of-computing.com/tc/CS/iconprog.pdf Icon HandBook]
procedure main()
sieve(100)
end
procedure sieve(n)
local p,i,j
p:=repl("1",n)
every i:=2 to sqrt(n) do
if p[i] == "1" then
every j:= i+i to n by i do p[j]:="0"
every i:=2 to n do if p[i]=="1" then write(i)
end
 
=={{header|J}}==