Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
using Stream rather than fixed Range
Browse files Browse the repository at this point in the history
  • Loading branch information
trenton committed Oct 29, 2009
1 parent b76dfa6 commit 49879a8
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions scala/002/01.scala
Expand Up @@ -18,8 +18,7 @@ def acc_tr_helper(n: Int, sum: Int): Int = n match {
}

val maxAllowedValue = 4000000
// perhaps a Projection to infinity instead?
val fibLessThanMax = (1 to Integer.MAX_VALUE).map(fib(_)).takeWhile(_ < maxAllowedValue)
val fibLessThanMax = Stream.from(1).map(fib(_)).takeWhile(_ < maxAllowedValue)
println(fibLessThanMax.filter(_ % 2 == 0).foldLeft(0L)(_ + _))

// http://oldfashionedsoftware.com/2009/07/30/lots-and-lots-of-foldleft-examples/

0 comments on commit 49879a8

Please sign in to comment.