Skip to content

Instantly share code, notes, and snippets.

@marcincembrzynski
Last active June 30, 2017 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcincembrzynski/c23f514dd0fa77c415a678a71334d107 to your computer and use it in GitHub Desktop.
Save marcincembrzynski/c23f514dd0fa77c415a678a71334d107 to your computer and use it in GitHub Desktop.
-module(f2).
-export([product/1,maximum/1,productTail/1,productTail/2,maximumTail/1,maximumTail/2]).
product([X]) -> X;
product([X|XS]) -> X * product(XS).
productTail(L) -> productTail(L,1).
productTail([],P) -> P;
productTail([X|XS],P) -> productTail(XS,P * X).
maximum([X]) -> X;
maximum([X|XS]) -> max(X,maximum(XS)).
maximumTail([X|[]]) -> X;
maximumTail([X,Y|XS]) -> maximumTail(XS,max(X,Y)).
maximumTail([],M) -> M;
maximumTail([X|XS], M) -> maximumTail(XS, max(X,M)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment