Skip to content

Instantly share code, notes, and snippets.

@mshirdel

mshirdel/prime.rb

Created Apr 19, 2018
Embed
What would you like to do?
prime number up to 1M
def is_prime(num)
(2..(num ** 0.5).to_i).each { |n| return false if num % n == 0 }
true
end
number_of_primes = 0
(2..1000000).each { |n| number_of_primes += 1 if is_prime n }
puts number_of_primes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment