Last active
May 7, 2020 13:51
-
-
Save 2torus/b7e70860767e58ceb2245ca32480276a to your computer and use it in GitHub Desktop.
Second exercise in "Future Learn/Programming Erlang".
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(ex2). | |
-export([max_three/3, how_many_equal/3, how_many_equal_test/0, xor1/2, xor2/2, xor3/2]). | |
xor1(true, B) -> | |
not B; | |
xor1(_, B) -> | |
B. | |
xor2(A, false)-> | |
A; | |
xor2(false, B)-> | |
B; | |
xor2(_, _) -> | |
false. | |
xor3(A, B) -> | |
A =/= B. | |
max_three(A,B,C) -> | |
max(A, max(B, C)). | |
how_many_equal(X, X, X) -> 3; | |
how_many_equal(_, X, X) -> 2; | |
how_many_equal(X, _, X) -> 2; | |
how_many_equal(X, X, _) -> 2; | |
how_many_equal(_, _, _) -> 0. | |
how_many_equal_test() -> | |
[ | |
how_many_equal(1,1,1) == 3, | |
how_many_equal("a", "b", "a") == 2, | |
how_many_equal("a", 3, 4) == 0, | |
how_many_equal("a", "a", 2) == 2 | |
]. |
Thanks @elbrujohalcon. Updated the function names following your remarks. Too many Java habits :-(
😅
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice solution!
Stylistic/idiomatic Tip: It's more common in the Erlang community to use
snake_case
instead ofcamelCase
for functions, modules, and atoms in general. Test frameworks likeeunit
, for instance, expect your test functions to be calledsomething_something_test/0
.