Last active
February 28, 2017 13:02
-
-
Save klimisa/afd177b94394d6841b8af53e0f0e723e to your computer and use it in GitHub Desktop.
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
% Direct recursion | |
product([])-> | |
1; | |
product([X|Xs])->X*product(Xs). | |
% Tail recursion | |
product(Xs)->product(Xs,1). | |
product([],P)-> | |
P; | |
product([X|Xs],P)->product(Xs,P*X). | |
% Direct recursion | |
maximum([X])-> | |
X; | |
maximum([X,Y|Xs])-> | |
maximum([max(X,Y)|Xs]). | |
% Tail recursion | |
maximum(Xs)-> | |
maximum(Xs,0). | |
maximum([X],M)-> | |
max(X,M); | |
maximum([X|Xs],M)-> | |
maximum(Xs, max(X,M)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment