Created
October 27, 2014 09:08
-
-
Save CMCDragonkai/fa854483835dfa32ba0f to your computer and use it in GitHub Desktop.
Nix: Dynamic Fibonnaci in Functional Style O(n)
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
let | |
fib = number: fib' number 1 1; | |
fib' = number: first: second: | |
if number == 0 | |
then first | |
else fib' (number - 1) second (first + second); | |
# the second becomes the new first, the (first + second) becomes the new second | |
in | |
fib 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment