Skip to content

Instantly share code, notes, and snippets.

@asbubam
Created June 1, 2013 15:33
Show Gist options
  • Save asbubam/5690764 to your computer and use it in GitHub Desktop.
Save asbubam/5690764 to your computer and use it in GitHub Desktop.
Euler scala Ex07
/*
소수를 크기 순으로 나열하면 2, 3, 5, 7, 11, 13, ... 과 같이 됩니다.
이 때 10,001번째의 소수를 구하세요.
*/
object Ex07 extends App {
var n = 0
var count = 0
while(count != 10001) {
n += 1;
if(isPrime(n)) count += 1
}
println(n);
def isPrime(n: Int) : Boolean = {
if (n <= 1)
false
else if (n == 2)
true
else
!(2 to (n-1)).exists(x => n % x == 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment