Last active
December 19, 2015 17:48
-
-
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?
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
$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