Created
February 20, 2017 23:15
-
-
Save fedeisas/0310b94fc80ba9e62656f96a4b566ad7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
% Fibonacci numbers | |
% The Fibonacci sequence is given by 0, 1, 1, 2, 3, 5, … where subsequent values are given by adding the two previous values in the sequence. | |
% | |
% Give a recursive definition of the function fib/1 computing the Fibonacci numbers, and give a step-by-step evaluation of fib(4). | |
% | |
% Usage: | |
% lists:map(fun(X) -> fibonacci:fib(X) end, lists:seq(0, 10)). | |
-module(fibonacci). | |
-export([fib/1]). | |
fib(0) -> | |
0; | |
fib(1) -> | |
1; | |
fib(X) when X > 0 -> | |
fib(X-1) + fib(X-2). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment