Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Created October 27, 2014 09:08
Show Gist options
  • Save CMCDragonkai/fa854483835dfa32ba0f to your computer and use it in GitHub Desktop.
Save CMCDragonkai/fa854483835dfa32ba0f to your computer and use it in GitHub Desktop.
Nix: Dynamic Fibonnaci in Functional Style O(n)
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