Created
April 17, 2013 14:25
-
-
Save mbc9news/5404731 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
//http://euler.synap.co.kr/prob_detail.php?id=2 | |
//피보나치 수열의 각 항은 바로 앞의 항 두 개를 더한 것이 됩니다. 1과 2로 시작하는 경우 이 수열은 아래와 같습니다. | |
//1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... | |
//짝수이면서 4백만 이하인 모든 항을 더하면 얼마가 됩니까? | |
class Euler_002 { | |
def evenFiboSum(x:Int){ | |
var tmp1 = 1 | |
var tmp2 = 2 | |
var tmp = 0 | |
var sum = 0 | |
while(tmp2 < x){ | |
if(tmp2%2 == 0) sum += tmp2 | |
tmp = tmp2 | |
tmp2 += tmp1 | |
tmp1 = tmp | |
} | |
println("["+x+"]["+sum+"]") | |
} | |
} | |
object Euler_002 extends App { | |
new Euler_002().evenFiboSum(10) | |
new Euler_002().evenFiboSum(4000000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment