fork download
  1. object Main extends App { // code by stewSquared , from
  2. // your code goes here // http://stackoverflow.com/q/20985539/849891,
  3. def primes(): Stream[Int] = { // basis for mMaJOa
  4. def merge(a: Stream[Int], b: Stream[Int]): Stream[Int] = {
  5. def next = a.head min b.head
  6. Stream.cons(next, merge(if (a.head == next) a.tail else a,
  7. if (b.head == next) b.tail else b))
  8. }
  9. def test(n: Int, compositeStream: Stream[Int]): Stream[Int] = {
  10. if (n == compositeStream.head) test(n+1, compositeStream.tail)
  11. else Stream.cons(n,
  12. test(n+1, merge(compositeStream, Stream.from(n*n, n))))
  13. }
  14. test(2, Stream.from(4, 2))
  15. }
  16. // 2:0.39s-382M 100:0.41s-382M 200: 0.42s-382M zero-time=0.39s
  17. print(primes().drop(1100).head)
  18. // 500: 0.59s-382M 1000:1.97s-383M n^2.98
  19. } // 1100:2.54s-384M n^3.23(vs 1000) n^3.0(vs 500)
Success #stdin #stdout 2.54s 384000KB
stdin
Standard input is empty
stdout
8837