Created
March 10, 2017 21:11
-
-
Save rwngallego/a27d9c2db824390c6de0b3ece7fd4a66 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
-module(lists_module). | |
-export([product/1, maximum/1, product_t/1, maximum_t/1]). | |
% direct | |
product([]) -> | |
1; | |
product([H|T]) -> | |
H*product(T). | |
maximum([H|[]]) -> | |
H; | |
maximum([H|T]) -> | |
max(H, maximum(T)). | |
% tail | |
product_t([_|_]=L) -> product_t(L, 1). | |
product_t([], N) -> N; | |
product_t([H|T], N) -> product_t(T, N*H). | |
maximum_t([_|_]=L) -> | |
maximum_t(L, 0). | |
maximum_t([], N) -> | |
N; | |
maximum_t([H|T], N) -> | |
maximum_t(T, max(H, N)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment