Skip to content

Instantly share code, notes, and snippets.

@2torus
Last active May 7, 2020 13:51
Show Gist options
  • Save 2torus/b7e70860767e58ceb2245ca32480276a to your computer and use it in GitHub Desktop.
Save 2torus/b7e70860767e58ceb2245ca32480276a to your computer and use it in GitHub Desktop.
Second exercise in "Future Learn/Programming Erlang".
-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
].
@elbrujohalcon
Copy link

Nice solution!
Stylistic/idiomatic Tip: It's more common in the Erlang community to use snake_case instead of camelCase for functions, modules, and atoms in general. Test frameworks like eunit, for instance, expect your test functions to be called something_something_test/0.

@2torus
Copy link
Author

2torus commented May 7, 2020

Thanks @elbrujohalcon. Updated the function names following your remarks. Too many Java habits :-(

@elbrujohalcon
Copy link

😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment