Skip to content

Instantly share code, notes, and snippets.

@fedeisas
Created February 20, 2017 23:15
Show Gist options
  • Save fedeisas/0310b94fc80ba9e62656f96a4b566ad7 to your computer and use it in GitHub Desktop.
Save fedeisas/0310b94fc80ba9e62656f96a4b566ad7 to your computer and use it in GitHub Desktop.
% 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