Last active
May 11, 2020 07:31
-
-
Save 2torus/a9968da49f32d7b039855ed7e3d984b1 to your computer and use it in GitHub Desktop.
Exercise 2.15 of FutureLearn class on Erlang
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(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)). |
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
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 usemax/2
instead?