Skip to content

Instantly share code, notes, and snippets.

@randomecho

randomecho/patterns.erl

Last active Mar 3, 2017
Embed
What would you like to do?
-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