fork(1) 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.49s 322176KB
stdin
11
12
45
5
4
25
23
21
20
10
12
26
stdout
48
29 ms elapsed