Skip to content

Instantly share code, notes, and snippets.

@dnunez24
Created May 6, 2014 16:02
Show Gist options
  • Save dnunez24/9743514c40c5daf93558 to your computer and use it in GitHub Desktop.
Save dnunez24/9743514c40c5daf93558 to your computer and use it in GitHub Desktop.
Erlang Fibonacci
-module(fibonacci).
-export([seq/1, sum/1]).
seq(0) -> [0];
seq(1) -> [0, 1];
seq(N) when N > 1 ->
lists:reverse(seq(N, [1, 0])).
seq(1, Acc) -> Acc;
seq(N, Acc = [H1, H2 | _T]) ->
seq(N - 1, [H1 + H2 | Acc]).
sum(N) ->
lists:sum(seq(N)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment