Created
May 9, 2020 18:24
-
-
Save pppillai/833fc45c0ffce2cf04ada2d85a905bba 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(week1). | |
-export([xOr_first_impl/2, xOr_second_impl/2, xOr_third_impl/2, maxThree/3, howManyEqual/3 | |
, test_howManyEqual_function/0, test_maxThree_function/0, test_xOrImpl_function/0]). | |
%xOr implementations. | |
xOr_first_impl(A, B) -> | |
A =/= B. | |
xOr_second_impl(A, B) -> | |
not (A == B). | |
xOr_third_impl(A, B) -> | |
(not A and B) or (A and not B). | |
%max of three numbers | |
maxThree(First, Second, Third) -> | |
max(First, max(Second, Third)). | |
%Number Equal arguments in three | |
howManyEqual(First, First, First) -> | |
3; | |
howManyEqual(First, First, _) -> | |
2; | |
howManyEqual(First, _, First) -> | |
2; | |
howManyEqual(_, First, First) -> | |
2; | |
howManyEqual(_, _, _) -> | |
0. | |
% | |
%test functions | |
% | |
test_howManyEqual_function() -> | |
(howManyEqual(3,3,3) == 3) and | |
(howManyEqual(1,3,3) == 2) and | |
(howManyEqual(3,1,3) == 2) and | |
(howManyEqual(3,3,1) == 2) and | |
(howManyEqual(1,2,3) == 0). | |
test_maxThree_function() -> | |
(maxThree(1,2,3) == 3) and | |
(maxThree(1,1,1) == 1) and | |
(maxThree(-1, 0, -2) == 0). | |
test_xOrImpl_function() -> | |
(xOr_first_impl(true, false) == true) and | |
(xOr_first_impl(true, true) == false) and | |
(xOr_first_impl(false, true) == true). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A good solution.
Stylistic Tip: It's more common in Erlang to use snake_case, instead of pascalCase for functions, modules, and atoms in general.