Sha256: 752a24630698ef0c0f8d98c94d89dc05bb8d4f88df8643582d9ec819e4ecdfb0
Contents?: true
Size: 586 Bytes
Versions: 155
Compression:
Stored size: 586 Bytes
Contents
class Prime { private static def isPrime(int n) { def sqrt = Math.ceil(Math.sqrt(n)) for (int i = 3; i <= sqrt; i += 1 ) { if ( n % i == 0 ) { return false } } return true } static nth(int n) { // handle stuff that doesn't need // additional calculations if ( n < 1 ) throw new ArithmeticException() if ( n == 1 ) return 2 def lastValue = 0 def count = 1 def i = 3 while ( count < n ) { if ( isPrime(i) ) { lastValue = i count += 1 } i += 2 } return lastValue } }
Version data entries
155 entries across 155 versions & 1 rubygems