Created
October 18, 2014 22:13
-
-
Save stanpalatnik/cfd50e415a584ddaa603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.annotation.tailrec | |
import scala.collection.mutable | |
object Euler02 extends App { | |
@tailrec | |
def fib(num: Int, prev: Int, result: mutable.Builder[Int, Vector[Int]] = Vector.newBuilder[Int]): Vector[Int] = { | |
num match { | |
case 0 => result.result() | |
case x if x > 4000000 => result.result() | |
case x if x >= 1 => { | |
if(num%2 == 0) result += x | |
fib(x + prev, x, result) | |
} | |
} | |
} | |
print(fib(1, 0).sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment