Skip to content

Instantly share code, notes, and snippets.

@AndrewGuard
Created January 10, 2014 20:48
Show Gist options
  • Save AndrewGuard/8362288 to your computer and use it in GitHub Desktop.
Save AndrewGuard/8362288 to your computer and use it in GitHub Desktop.
# 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