Created
June 7, 2016 16:20
-
-
Save vigdorchik/bdd042effb33f6d9fdab37fdd7e82c13 to your computer and use it in GitHub Desktop.
haskell fibonacci
This file contains hidden or 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
fib = map fib' [0..] where | |
fib' 0 = 0; fib' 1 = 1; fib' n = (fib !! (n-1))+(fib !! (n-2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or linearly:
fib = map fst $ iterate ((n_2,n_1) -> (n_1, n_2+n_1)) (1,1)