Created
February 20, 2017 22:01
-
-
Save fedeisas/4679c4701d7541ba397024d812f16f0b to your computer and use it in GitHub Desktop.
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(maxThree). | |
-export([maxThree/3]). | |
maxThree(X, X, X) -> | |
X; | |
maxThree(X, X, Y) -> | |
case max(X, Y) of | |
X -> X; | |
Y -> Y | |
end; | |
maxThree(X, Y, X) -> | |
case max(X, Y) of | |
X -> X; | |
Y -> Y | |
end; | |
maxThree(Y, X, X) -> | |
case max(X, Y) of | |
X -> X; | |
Y -> Y | |
end; | |
maxThree(X, Y, Z) -> | |
case max(X, Y) of | |
X -> | |
case max(X, Z) of | |
X -> X; | |
Z -> Z | |
end; | |
Y -> | |
case max(Y, Z) of | |
Y -> Y; | |
Z -> Z | |
end | |
end. |
Seems to work with order capable values:
83> one_fifteen:maxThree(a,b,c).
c
84> one_fifteen:maxThree(c,a,b).
c
85> one_fifteen:maxThree("foo","bar","baz").
"foo"
@scull7, the first 3 patterns are not necessary as they are also covered by the last one.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are the case statements necessary? These seemed to work, though they might fail for strange values.