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.0.1 tracks/scala/exercises/nth-prime/example.scala
trackler-2.2.0.0 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.55 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.54 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.53 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.52 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.51 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.50 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.49 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.48 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.47 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.46 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.45 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.44 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.43 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.42 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.41 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.40 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.39 tracks/scala/exercises/nth-prime/example.scala
trackler-2.1.0.38 tracks/scala/exercises/nth-prime/example.scala