Skip to content

Instantly share code, notes, and snippets.

@randomecho
Last active March 3, 2017 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomecho/d2cdfd854a4e9d5947707eedf19fee30 to your computer and use it in GitHub Desktop.
Save randomecho/d2cdfd854a4e9d5947707eedf19fee30 to your computer and use it in GitHub Desktop.
-module(patterns).
-export([exxor/2,exxot/2,exxon/2,efix/2,maxThree/3,howManyEqual/3]).
exxor(X,Y) ->
X =/= Y.
exxot(X,Y) ->
X == Y.
exxon(X,Y) ->
not (X == Y).
efix(X,Y) ->
(X == Y) and (X > Y).
maxThree(X,Y,Z) ->
max(max(X,Y),Z).
howManyEqual(X,X,X) -> 3;
howManyEqual(X,X,_) -> 2;
howManyEqual(X,_,X) -> 2;
howManyEqual(_,X,X) -> 2;
howManyEqual(_,_,_) -> 0.
-module(recursion).
-export([fib/1,pieces/1]).
fib(1) ->
1;
fib(2) ->
1;
fib(X) when X > 0 ->
fib(X-1) + fib(X-2).
pieces(1) ->
2;
pieces(X) when X > 0 ->
pieces(X-1) + X.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment