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.1.0.37 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.36 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.34 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.33 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.32 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.31 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.30 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.29 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.28 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.27 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.26 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.25 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.24 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.23 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.22 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.21 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.20 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.19 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.18 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.17 tracks/scala/exercises/nth-prime/example.scala