Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
end_value = 120
#-- Using mod
a = Array(2..end_value)
limit = Math.sqrt end_value
a.each do |x|
a.delete_if do |y|
next if y <= x
y % x == 0
end
break if x >= limit
end
puts "Primes: #{a}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment