Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View sieve_of_euler.rb
1 2 3 4 5 6 7 8 9 10
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.