Skip to content

Instantly share code, notes, and snippets.

@Joakineee
Joakineee / trecursive.erl
Last active May 14, 2020 10:25
Tail recursive erlang
-module(trecursive).
-export([fib/1,perfect/1,test/0]).
fib(X) -> fib(X,0,1).
fib(0,Acc1,_) ->
Acc1;
fib(X,Acc1,Acc2) when X >= 1 ->
@Joakineee
Joakineee / recursive.erl
Last active May 12, 2020 14:43
Recursive exercise
-module(recursive).
-export([fib/1,pieces/1]).
fib(0) -> 0;
fib(1) -> 1;
fib(X) when X > 1-> fib(X-2) + fib(X-1).
%Steep by steep evaluation:
%fib(4) -> fib(2) + fib(3)
@Joakineee
Joakineee / pattern_matching.erl
Last active May 8, 2020 06:56
Pattern Matching exercise
-module(pattern_matching).
-export([xOr_1/2,xOr_2/2,xOr_3/2,xOr_4/2,test_xOr_1/0,test_xOr_2/0,test_xOr_3/0,test_xOr_4/0,test_maxThree/0,test_howManyEqual/0]).
xOr_1(X,Y) ->
X =/= Y.
xOr_2(X,Y) ->
(X and not Y) or (not X and Y).
@Joakineee
Joakineee / first.erl
Created May 6, 2020 14:18
My first Erlang program
-module(first).
-export([double/1,mult/2,area/3,square/1,treble/1]).
mult(X,Y) ->
X*Y.
double(X) ->
@Joakineee
Joakineee / second.erl
Created May 6, 2020 14:16
My first Erlang program
-module(second).
-export([hypotenuse/2,perimeter/2,area/2]).
hypotenuse(X,Y) ->
math:sqrt(first:square(X) + first:square(Y)).
perimeter(X,Y) ->