Created
September 26, 2012 17:24
-
-
Save banacorn/3789342 to your computer and use it in GitHub Desktop.
fib 1000000
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
import Data.List | |
import Data.Bits | |
fib :: Int -> Integer | |
fib n = snd . foldl' fib' (1, 0) . dropWhile not $ | |
[testBit n k | k <- let s = bitSize n in [s-1,s-2..0]] | |
where | |
fib' (f, g) p | |
| p = (f*(f+2*g), ss) | |
| otherwise = (ss, g*(2*f-g)) | |
where ss = f*f+g*g | |
main = print $ fib 1000000 |
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
ghc fib.hs | |
time ./fib |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment