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 (odd) $ 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
EDIT:
If anyone is interested, I've solved this problem. Here is the code (very clumsy-looking, but works nevertheless):
findsum threshold = findsum' 0 1 0 threshold
findsum' n1 n2 accu t
| n2 > t = accu
| odd n2 = findsum' n2 n3 accu t
| otherwise = findsum' n2 n3 accu2 t
where
n3 = n2 + n1
accu2 = accu + n2