fork download
  1. import scala.concurrent.duration._
  2.  
  3. object Main extends App {
  4. val input = Stream.continually(readLine()).takeWhile(null ne).map(_.toInt)
  5.  
  6. def products(stream: Stream[Int]): Stream[Int] = stream match {
  7. case Stream.Empty
  8. Stream.Empty
  9.  
  10. case x #:: xs ⇒
  11. xs.drop(5).map(_ * x) #::: products(xs)
  12. }
  13.  
  14. val start = System.nanoTime()
  15. println(products(input).min)
  16. println(s"${(System.nanoTime() - start).nanos.toMillis} ms elapsed")
  17. }
Success #stdin #stdout 0.44s 322240KB
stdin
11
12
45
5
12
25
23
21
20
10
4
26
stdout
20
28 ms elapsed