10 ms·
Too late to edit, but if you do fib(N) when ... -> fib(N - 2, fib(0) + fib(1), fib(1)). Then you can check for N = 0 to return Current, and do N - 1 in the it
by toast0 5y ago
Too late to edit, but if you do
fib(N) when ... -> fib(N - 2, fib(0) + fib(1), fib(1)).
Then you can check for N = 0 to return Current, and do N - 1 in the iteration. One less value to pass in each recursion should make it faster, and it's less to think about.