Created
January 10, 2014 20:48
-
-
Save AndrewGuard/8362288 to your computer and use it in GitHub Desktop.
This file contains 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
# Problem #7 from http://projecteuler.net/problem=7 | |
def prime? x | |
a = Math.sqrt(x) | |
(2..a).each {|y| return false if x % y == 0} | |
true | |
end | |
def prime_value(index) | |
val = 3 | |
counter = 1 | |
while true | |
counter +=1 if prime?(val) | |
break if counter == index | |
val += 2 | |
end | |
puts "The answer is #{val}" | |
end | |
prime_value(10001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment