I have to write a program to implement the Sieve of Erastosthenes
algorithm for finding the prime nos.
I got the following code on scriptol.org
top = 100
sieve = []
for i in 2 … top
sieve[i] = i
end
for i in 2 … Math.sqrt(top)
next unless sieve[i]
(i*i).step(top, i) do |j|
sieve[j] = nil
end
end
puts sieve
Can someone please tell me what’s happening in the lines
next unless sieve[i]
(i*i).step(top,i) do |j|
sieve[j]=nil