Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.39 KB | None | 0 0
  1. -module(practice).
  2. -export([product/1, max_of_list/1]).
  3.  
  4. % Return the product of the elements of the list
  5. product(X) -> product(X, 1).
  6. product([], Acc) -> Acc;
  7. product([X|Xs], Acc) -> product(Xs, X*Acc).
  8.  
  9. % Return the max of the list
  10. max_of_list([X|Xs]) -> max_of_list(Xs, X).
  11. max_of_list([X], Max) -> erlang:max(X, Max);
  12. max_of_list([X|Xs], Max) -> max_of_list(Xs, erlang:max(X, Max)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement