Created
May 22, 2011 21:10
-
-
Save johana-star/985898 to your computer and use it in GitHub Desktop.
Find the 10001st prime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def evaluate_for_primes(primes, count) | |
numbers = (primes[count-1]**2+1..primes[count]**2).to_a | |
1.upto(count) {|c| numbers.select! {|number| number%primes[c] != 0}} | |
primes.concat(numbers) | |
end | |
primes, count = [1, 2], 1 | |
until primes.length > 10001 do | |
evaluate_for_primes(primes, count) | |
count += 1 | |
end | |
p primes[10001] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment