Skip to content

Instantly share code, notes, and snippets.

@fbiville
Last active August 29, 2015 14:12
Show Gist options
  • Save fbiville/daf8795a777c039cf8e3 to your computer and use it in GitHub Desktop.
Save fbiville/daf8795a777c039cf8e3 to your computer and use it in GitHub Desktop.
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