Created
June 23, 2017 21:09
-
-
Save apbarrero/a66f7e3eb8202856a0a0fe5d73c9fc59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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