Solving euler project #2 via haskell was a good challenge. Here is the modified solution once I found you can take each 3 in the fibonacci sequence instead of checking for even.
naturals n = n : naturals (n+1)
fib :: Integer→ Integer
fib n = round((phi↑n - (1-phi)↑n) / sqrt 5)
where phi = (1+sqrt 5)/2
sum' = sum (takeWhile (<4000000) (map fib (map (λx→ x*3) (naturals 1))))
No comments:
Post a Comment