Skip to content

Instantly share code, notes, and snippets.

@sushant12
Created May 5, 2020 01:02
Show Gist options
  • Save sushant12/5d47a6e0641c38d211c92414b9958c73 to your computer and use it in GitHub Desktop.
Save sushant12/5d47a6e0641c38d211c92414b9958c73 to your computer and use it in GitHub Desktop.
-module(assignment2).
-export([maxThree/3, howManyEqual/3]).
maxThree(X,Y,Z) ->
case lists:sort([X,Y,Z]) of
[_,_,M] -> M;
_ -> 0
end.
howManyEqual(X, X, X) -> 3;
howManyEqual(X, X, _) -> 2;
howManyEqual(_, X, X) -> 2;
howManyEqual(X, _, X) -> 2;
howManyEqual(_, _, _) -> 0.
@elbrujohalcon
Copy link

Good solution, but using lists:sort/1 is cheating ;)

@EarlOfBDE
Copy link

@elbrujohalcon

Good solution, but using lists:sort/1 is cheating ;)
Is there a real difference, though? Does 'lists/sort/1' put things in a different order than using max()? I.e. is one numerical/binary while the other is ???

@elbrujohalcon
Copy link

no, no... The code is fine. It's just that the course did not go over list functions yet ;)

@sushant12
Copy link
Author

@elbrujohalcon @EarlOfBDE the reason I used lists:sort/1 instead of max is because I wanted to do pattern matching here. :)

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