Last active
September 5, 2016 07:13
-
-
Save rayyildiz/065e2ee6c64b3ac215ad84b05f67c793 to your computer and use it in GitHub Desktop.
Even Fibonacci numbers (Project Euler Question 2)
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
fib :: Integer -> Integer | |
fib 0 = 1 | |
fib 1 = 1 | |
fib n = fib (n-1) + fib (n-2) | |
fibs = take 40 (1 : 1 : zipWith (+) fibs (tail fibs)) | |
fibResult = sum [x | x <- fibs, x < 4000000, x `mod` 2 == 0 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.