Skip to content

Instantly share code, notes, and snippets.

@astronomy88
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astronomy88/9635685 to your computer and use it in GitHub Desktop.
Save astronomy88/9635685 to your computer and use it in GitHub Desktop.
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