Skip to content

Instantly share code, notes, and snippets.

@atushi
Last active December 19, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atushi/5993586 to your computer and use it in GitHub Desktop.
Save atushi/5993586 to your computer and use it in GitHub Desktop.
Project Euler . Problem 7 . 10001st prime : By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number?
$TARGETNUM = 10001
$primeNum = []
$i = 1
$cnt = 0
loop do
flag = true
x = 2
while x<$i
# p x
if $i % x==0 then
flag = false
break
end
x += 1
end
if flag then
$primeNum.push($i)
p "[#{$cnt.to_i}] : #{$i.to_i}" if $cnt>0
break if $cnt == $TARGETNUM
$cnt += 1
end
$i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment