Created
May 7, 2020 16:00
-
-
Save jameswalton/e53687868a8ebc6281f0f8163e7a8f9a to your computer and use it in GitHub Desktop.
Variables and patterns in practice
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(variables_patterns_exercise). | |
-export([test/0]). | |
test() -> | |
0 = how_many_equal(34,25,36), | |
2 = how_many_equal(34,25,34), | |
2 = how_many_equal(34,34,25), | |
2 = how_many_equal(25,34,34), | |
3 = how_many_equal(34,34,34), | |
9 = maximum_of_three(3,6,9), | |
100 = maximum_of_three(100,50,25), | |
0.3 = maximum_of_three(0.1, 0.3, 0.2), | |
true = x_or1(true, false), | |
true = x_or1(false, true), | |
false = x_or1(true, true), | |
false = x_or1(false, false), | |
true = x_or2(true, false), | |
true = x_or2(false, true), | |
false = x_or2(true, true), | |
false = x_or2(false, false), | |
true = x_or3(true, false), | |
true = x_or3(false, true), | |
false = x_or3(true, true), | |
false = x_or3(false, false), | |
ok. | |
x_or1(X, Y) -> not(X == Y). | |
x_or2(X,Y) -> X =/= Y. | |
x_or3(X,Y) -> (X or Y) and not(X and Y). | |
how_many_equal(X,X,X) -> 3; | |
how_many_equal(X,X,_Y) -> 2; | |
how_many_equal(X,_Y,X) -> 2; | |
how_many_equal(_Y,X,X) -> 2; | |
how_many_equal(_X,_Y,_Z) -> 0. | |
maximum_of_three(X,Y,Z) -> max(max(X,Y),Z). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Niiiice :)