tracks/kotlin/exercises/nth-prime/.meta/src/reference/kotlin/Prime.kt in trackler-2.2.1.62 vs tracks/kotlin/exercises/nth-prime/.meta/src/reference/kotlin/Prime.kt in trackler-2.2.1.63

- old
+ new

@@ -1,10 +1,15 @@ import java.math.BigInteger object Prime { - fun nth(n: Int): Int = primes().drop(n - 1).first().toInt() + fun nth(n: Int): Int { + require(n > 0) { "There is no zeroth prime." } - fun primes(): Sequence<BigInteger> = generateSequence(BigInteger.valueOf(2)) { previous -> + return primes().drop(n - 1).first().toInt() + } + + private fun primes(): Sequence<BigInteger> = generateSequence(BigInteger.valueOf(2)) { previous -> previous.nextProbablePrime() } + }