Skip to content

Instantly share code, notes, and snippets.

@ubaldop
Created February 26, 2017 11:40
Show Gist options
  • Save ubaldop/9796cd36e0d535f05e779acef4cc487c to your computer and use it in GitHub Desktop.
Save ubaldop/9796cd36e0d535f05e779acef4cc487c to your computer and use it in GitHub Desktop.
Second homework solution, Erlang course.
-module(pattern_matching).
-export([exclusiveOr/2,exclusiveOr2/2,exclusiveOr3/2, maxThree/3, howManyEquals/3]).
exclusiveOr(X,Y) ->
not(X==Y).
exclusiveOr2(X,Y) ->
(X=/=Y).
exclusiveOr3(X,Y) when (X and Y) -> false;
exclusiveOr3(X,Y) when not (X or Y) -> false;
exclusiveOr3(_,_) -> true.
maxThree(X,Y,Z) when ((X > Z) or (Y > Z)) -> max(X,Y);
maxThree(_,_,Z) -> Z.
howManyEquals(X,X,X) -> 3;
howManyEquals(X,Y,Z) when (X == Y) or (X == Z) or (Y == Z) -> 2;
howManyEquals(_,_,_) -> 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment