3 ms·
> And then you get told that this is simple but very inefficient. You see an efficient loop implementation afterwards and agree. And then you're shown that a f
by dozzie 9y ago
> And then you get told that this is simple but very inefficient. You see an efficient loop implementation afterwards and agree.
And then you're shown that a function can return a tuple.
-module(fib).
-export([fib/1]).
fib(N) ->
{A, _} = fib2(N),
A.
fib2(1) ->
{1, 0};
fib2(N) ->
{A, B} = fib2(N - 1),
{A + B, A}.