Created
May 7, 2020 03:50
-
-
Save tr00gle/9ff158a25d19f2f0cd344c92be5c888d 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(pattern_matching_practice). | |
-export([test/0]). | |
xOr(X,X) -> | |
false; | |
xOr(_,_) -> | |
true. | |
exclusive_or(X, Y) when X =/= Y -> true; | |
exclusive_or(_,_) -> false. | |
ex_or(X,Y) when not(X == Y) -> true; | |
ex_or(_,_) -> false. | |
maxThree(A, A, A) -> A; | |
maxThree(A, B, C) when A > B, A > C -> A; | |
maxThree(A, B, C) when B > A, B > C -> B; | |
maxThree(A, B, C) when C > A, C > B -> C. | |
howManyEqual(A, A, A) when is_integer(A) -> 3; | |
howManyEqual(A, A, B) when is_integer(A), is_integer(B) -> 2; | |
howManyEqual(A, B, A) when is_integer(A), is_integer(B) -> 2; | |
howManyEqual(B, A, A) when is_integer(A), is_integer(B) -> 2; | |
howManyEqual(_, _, _) -> 0. | |
test() -> | |
false = xOr(5, 5), | |
true = xOr(4, 5), | |
false = exclusive_or(5, 5), | |
true = exclusive_or(4, 5), | |
false = ex_or(5, 5), | |
true = ex_or(4, 5), | |
5 = maxThree(5, 5, 5), | |
8 = maxThree(8, 5, 6), | |
8 = maxThree(5, 6, 8), | |
8 = maxThree(5, 8, 6), | |
3 = howManyEqual(10, 10, 10), | |
2 = howManyEqual(5, 8, 8), | |
2 = howManyEqual(5, 5, 8), | |
2 = howManyEqual(5, 8, 5), | |
0 = howManyEqual(5, 6, 8), | |
ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment