Skip to content

Instantly share code, notes, and snippets.

@kingori
Created April 16, 2013 16:30
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 kingori/5397395 to your computer and use it in GitHub Desktop.
Save kingori/5397395 to your computer and use it in GitHub Desktop.
프로젝트 오일러 2번 풀이
class Euler2 {
/**
* max 이하의 짝수 피보나치 수열 합
* @param op1
* @param op2
* @param max
* @param sum
* @return
*/
def fibonacciEvenSum(op1: Int, op2: Int, max: Int, sum: Int): Int = {
val nextOp = op1 + op2
nextOp match {
case x if nextOp > max => sum
case x if nextOp % 2 == 0 => fibonacciEvenSum(op2, nextOp, max, sum + nextOp)
case _ => fibonacciEvenSum(op2, nextOp, max, sum)
}
}
}
object Euler2 extends App {
println( "sum:"+ new Euler2().fibonacciEvenSum(0,1, 4000000, 0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment