Created
May 7, 2020 23:38
-
-
Save sgobotta/791f404780f2e0d0b959b244126de283 to your computer and use it in GitHub Desktop.
Gist for the FeatureLearn Erlang course (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(recursion). | |
-export([fib/1, fibs/1, pieces/1]). | |
%% @doc given an integer computes it's position in the fibonacci sequence | |
fib(0) -> 0; | |
fib(1) -> 1; | |
fib(X) -> fib(X-1) + fib(X-2). | |
%% @doc given a fibonacci sequence position returns the sum of fibonacci computations | |
fibs(X) -> 1 + 1 + fibs(X-1) + fibs(X-2). | |
%% @doc given a number of cuts returns the maximum number of pieces obtained | |
pieces(0) -> 1; | |
pieces(N) -> pieces(N-1) + N. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment