Last active
May 12, 2020 14:43
-
-
Save Joakineee/6bd7e17a78e57e44597070db6d369d29 to your computer and use it in GitHub Desktop.
Recursive exercise
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
-module(recursive). | |
-export([fib/1,pieces/1]). | |
fib(0) -> 0; | |
fib(1) -> 1; | |
fib(X) when X > 1-> fib(X-2) + fib(X-1). | |
%Steep by steep evaluation: | |
%fib(4) -> fib(2) + fib(3) | |
%fib(4) -> (fib(0) + fib(1)) + (fib(1) + fib(2)) | |
%fib(4) -> (0 + 1 + 1 + (fib(0) + fib(1)) | |
%fib(4) -> (0 + 1 + 1 + 0 + 1). | |
pieces(0) -> 1; | |
pieces(X) when X > 0 -> X + pieces(X - 1). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment