Sum of Fibonacci numbers
Posted
by Rafal
on Stack Overflow
See other posts from Stack Overflow
or by Rafal
Published on 2010-05-05T20:52:18Z
Indexed on
2010/05/05
21:08 UTC
Read the original article
Hit count: 315
Hi,
I'm rather new to Haskell. The problem is to find the sum of all even Fibonacci numbers not greater than 4 million. I can't use lists.
If I understand correctly, the below solution is wrong, because it uses lists:
my_sum = sum $ filter (even) $ takeWhile (< 4000000) fibs
Where fibs is the list of all Fibonacci numbers.
Somehow, I find it difficult not to think in Haskell in terms of lists. Could anyone guide me to a solution to this problem?
Regards
© Stack Overflow or respective owner