Skip to content

Instantly share code, notes, and snippets.

-module(recursion).
-export([fac/1,fib/1,pieces/1,pieces_n_dimentions/2]).
%Factorial
fac(0) ->
1;
fac(N) when N>0 ->
fac(N-1)*N;
fac(_) ->
'error'.
-module(how_many_equal).
-export([howManyEqual/3]).
equal(X,X,X) ->
3;
equal(_,X,X) ->
2;
equal(X,X,_) ->
2;
equal(X,_,X) ->
-module(maximum_of_three).
-export([max_three/3]).
max_three(X,Y,Z) ->
max(max(X, Y),Z).
@juanelopezm
juanelopezm / exclusive_or.erl
Last active June 1, 2020 12:13
3 =/= ways to implement a xor
-module(exclusive_or).
-export([xor_1/2,xor_2/2,xor_3/2]).
%Testing with numbers and boolean values as well.
xor_1(X,Y) ->
(X=/=Y) or
false.
xor_2(X,Y) ->
-module(second).
-export([hypotenuse/2,hypotenuseMethod2/2,area4RightAngleTriangle/2,perimeter4RightAngleTriangle/3]).
hypotenuse(X,Y) ->
% hypotenuse of a right-angled triangle
A = first:squareNumber(X),
B = first:squareNumber(Y),
math:sqrt(A+B).
hypotenuseMethod2(X,Y) ->
-module(first).
-export([double/1,mult/2,area/3,squareNumber/1,trebleNumber/1]).
mult(X,Y) ->
X*Y.
double(X) ->
mult(2,X).
area(A,B,C) ->