Skip to content

Instantly share code, notes, and snippets.

@goz
Created June 1, 2010 21:35
Show Gist options
  • Save goz/421532 to your computer and use it in GitHub Desktop.
Save goz/421532 to your computer and use it in GitHub Desktop.
def prime_number(max)
arr = (2..max).to_a
(2..Math::sqrt(max)).each do |i|
arr.delete_if {|a|a % i == 0 && a!=i}
end
arr
end
# generate
# puts prime_number(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment