Skip to content

Instantly share code, notes, and snippets.

@stanpalatnik
Created October 18, 2014 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stanpalatnik/cfd50e415a584ddaa603 to your computer and use it in GitHub Desktop.
Save stanpalatnik/cfd50e415a584ddaa603 to your computer and use it in GitHub Desktop.
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