Last active
August 29, 2015 14:12
-
-
Save fbiville/daf8795a777c039cf8e3 to your computer and use it in GitHub Desktop.
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
fibonacci :: (Ord a, Num a) => a -> [a] | |
fibonacci limit = _fibonacci limit [1,2] | |
_fibonacci :: (Ord a, Num a) => a -> [a] -> [a] | |
_fibonacci limit x | |
| sum < limit = _fibonacci limit (x++[sum]) | |
| otherwise = x | |
where x1x2 = drop ((length x)-2) x | |
sum = ((head x1x2)+(last x1x2)) | |
foldl (+) 0 (filter (\n -> n `mod` 2 == 0) (fibonacci 4000000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment