Skip to content

Instantly share code, notes, and snippets.

@sleepynate
Created August 31, 2010 20:47
Show Gist options
  • Save sleepynate/559722 to your computer and use it in GitHub Desktop.
Save sleepynate/559722 to your computer and use it in GitHub Desktop.
{-
- Project Euler Problem 2
- Solution by nathan dotz - nathan (period) dotz (at sign) gmail (period) com
-
- 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:
- 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
-
- Find the sum of all the even-valued terms in the sequence
- which do not exceed four million.
-}
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
main = putStrLn $
"Sum of all even valued fibonacci numbers below 4 Million is: " ++
show ( sum [ fibs!!n | n <- [1..50]
,((fibs!!n) `mod` 2) == 0
, fibs!!n < 4000000 ] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment