Looking at Project Euler solutions at http://pavelfatin.com/scala-for-project-euler/ , I was a little embarrassed by what the view in the solution to "Problem 10 looks like. Calculate the sum of all primes below two million.
Proposed Solution:
lazy val ps: Stream[Int] = 2
... which leads to 142913828922
I noticed that you got a different result, 1179908154 , if you do not take the view into account:
val r = ps.takeWhile(_ < 2000000).foldLeft(0L)(_ + _)
Can someone explain to me why they are different?
source share