Skip to content

Instantly share code, notes, and snippets.

@apbarrero
Created June 23, 2017 21:09
Show Gist options
  • Save apbarrero/a66f7e3eb8202856a0a0fe5d73c9fc59 to your computer and use it in GitHub Desktop.
Save apbarrero/a66f7e3eb8202856a0a0fe5d73c9fc59 to your computer and use it in GitHub Desktop.
-module(recurs).
-export([fib/1, pieces/1]).
fib(1) ->
[0];
fib(2) ->
[1,0];
fib(N) when N>2 ->
L = fib(N-1),
[X|Xs] = L,
[Y|_] = Xs,
[X+Y] ++ L.
pieces(1) ->
2;
pieces(N) when N>1 ->
pieces(N-1) + N.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment