Created
May 13, 2020 06:12
-
-
Save tambow44/90fd6b94b46d55e64a3cdb1383102508 to your computer and use it in GitHub Desktop.
2nd week of Erlang on FutureLearn (2.3)
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 fourth. | |
-export[fac/1,fib/1,pieces/1]. | |
fac(0) -> | |
1; | |
fac(N) when (N > 0) -> | |
fac(N - 1) * N | |
. | |
fib(0) -> | |
0; | |
fib(1) -> | |
1; | |
fib(N) when (N > 0) -> | |
fib(N - 2) + fib(N - 1) | |
. | |
% Step through of 'fib(4)': | |
% __fib(4) | |
% = fib(2) + fib(3) | |
% = (fib(0) + fib(1)) + (fib(1) + fib(2)) | |
% = (0 + 1) + (1 + (fib(0) + fib(1))) | |
% = 1 + 1 + (0 + 1) | |
% = 1 + 1 + 1 | |
% = 3 | |
pieces(0) -> | |
1; | |
pieces(N) when (N > 0) -> | |
N + pieces(N-1) | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment