Skip to content

@hannestyden /sieve_of_euler.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
def sieve_of_euler(list)
if list.empty?
list
else
out = list - (list.map { |e| e * list.first })
[ out.first ] + sieve_of_euler(out[1..-1])
end
end
sieve_of_euler((2..30).to_a) # => [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.