Created
May 5, 2020 01:02
-
-
Save sushant12/5d47a6e0641c38d211c92414b9958c73 to your computer and use it in GitHub Desktop.
This file contains 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(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. |
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 ???
no, no... The code is fine. It's just that the course did not go over list functions yet ;)
@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
Good solution, but using
lists:sort/1
is cheating ;)