fork download
  1. object Main extends App {
  2. // code by John Landahl,
  3. // http://stackoverflow.com/questions/20985539/
  4. // scala-erastothenes-is-there-a-straightforward-way-to-
  5. // replace-a-stream-with-an/20991776#comment31606932_20986428
  6. val primes: Stream[Int] = 2 #:: Stream.from(3, 2).
  7. filter(i => primes.takeWhile(j => j * j <= i).
  8. forall(k => i % k > 0))
  9.  
  10. // 10: 0.39s-382M 100: 0.41s-382M zero_time=0.39s
  11. print(primes.drop(100000).head)
  12. // 10k: 0.62s-382M 25k: 1.02s-382M n^1.1
  13. } // 50k: 2.12s-382M n^1.46 100k: 5.11s-382M n^1.45
Success #stdin #stdout 5.11s 382144KB
stdin
Standard input is empty
stdout
1299721