Sha256: c576e1d51700e8142c2d0f0ca6951963944f57ceb54843305d4a38df70160b2a

Contents?: true

Size: 369 Bytes

Versions: 198

Compression:

Stored size: 369 Bytes

Contents

object Prime {
  // The stream will cache calculated primes. This is nice for performance,
  // but not so nice for memory utilization.
  private lazy val primes: Stream[BigInt] =
    Stream.cons(BigInt(2), primes.map(b => new BigInt(b.bigInteger.nextProbablePrime)))

  def nth(n: Int): Option[Int] =
    if (n < 1) None
    else Some(primes.drop(n - 1).head.toInt)
}

Version data entries

198 entries across 198 versions & 1 rubygems

Version Path
trackler-2.2.1.14 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.13 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.12 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.11 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.10 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.9 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.8 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.7 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.6 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.5 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.4 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.3 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.2 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.1 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.1.0 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.0.6 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.0.5 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.0.4 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.0.3 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.0.2 tracks/scala/exercises/nth-prime/example.scala