Skip to content

Instantly share code, notes, and snippets.

@2torus
Last active May 11, 2020 07:31
Show Gist options
  • Save 2torus/a9968da49f32d7b039855ed7e3d984b1 to your computer and use it in GitHub Desktop.
Save 2torus/a9968da49f32d7b039855ed7e3d984b1 to your computer and use it in GitHub Desktop.
Exercise 2.15 of FutureLearn class on Erlang
-module(ex2_15).
-export([prod/1, prod_tail/1, maxx/1, max_tail/1]).
prod([]) -> 1;
prod([X|Xs]) -> X * prod(Xs).
prod_tail(X) -> prod_tail(X, 1).
prod_tail([], P) -> P;
prod_tail([X|Xs], P) -> prod_tail(Xs, X * P).
maxx([S]) -> S;
maxx([X|Xs]) -> max(X, maxx(Xs)).
max_tail([X|Xs]) -> max_tail(Xs, X).
max_tail([], M) -> M;
max_tail([X|Xs], M) -> max_tail(Xs, max(X, M)).
@elbrujohalcon
Copy link

I'm not sure this code will even compile. I see a function maxx/2 used in line 13 while it's not defined anywhere. Maybe you wanted to use max/2 instead?

@2torus
Copy link
Author

2torus commented May 11, 2020

Hi @elbrujohalcon, you are absolutely right. I wanted to use max library function. Thanks for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment