progs/lecture3.scala
changeset 73 5e4696ebd8dc
parent 72 9d8b172f5337
child 77 3cbe3d90b77f
equal deleted inserted replaced
72:9d8b172f5337 73:5e4696ebd8dc
   290 def generatePrimes (s: Stream[Int]): Stream[Int] =
   290 def generatePrimes (s: Stream[Int]): Stream[Int] =
   291   s.head #:: generatePrimes(s.tail filter (_ % s.head != 0))
   291   s.head #:: generatePrimes(s.tail filter (_ % s.head != 0))
   292 
   292 
   293 val primes: Stream[Int] = generatePrimes(Stream.from(2))
   293 val primes: Stream[Int] = generatePrimes(Stream.from(2))
   294 
   294 
       
   295 primes.take(10).toList
       
   296 
   295 primes.filter(_ > 100).take(2000).toList
   297 primes.filter(_ > 100).take(2000).toList
   296 
   298 
   297 time_needed(1, primes.filter(_ > 100).take(2000).toList)
   299 time_needed(1, primes.filter(_ > 100).take(2000).toList)
   298 time_needed(1, primes.filter(_ > 100).take(2000).toList)
   300 time_needed(1, primes.filter(_ > 100).take(2000).toList)
   299 
   301