Skip to content

Instantly share code, notes, and snippets.

View Acentelles's full-sized avatar

Alberto Centelles Acentelles

  • London
View GitHub Profile
@Acentelles
Acentelles / frequency.erl
Created April 22, 2017 08:15
Concurrent Programming in Erlang: 1st week exercise
-module(frequency).
-export([start/0,allocate/0,deallocate/1,stop/0]).
-export([init/0]).
%% These are the start functions used to create and
%% initialize the server.
start() ->
register(frequency,
spawn(frequency, init, [])).
@Acentelles
Acentelles / second_week.erl
Created March 5, 2017 14:34
Second week - Index a file - FUNCTIONAL PROGRAMMING IN ERLANG - THE UNIVERSITY OF KENT
-module(index).
-export([get_file_contents/1,show_file_contents/1, find_index/2]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
% Get the contents of a text file into a list of lines.
@Acentelles
Acentelles / first_week.erl
Last active February 25, 2017 15:37
First week assignment - FUNCTIONAL PROGRAMMING IN ERLANG. THE UNIVERSITY OF KENT
perimeter({rectangle, {X, Y}, W, H}) -> 2 * W + 2 * H;
perimeter({square, {X, Y}, Side}) -> 4 * Side;
perimeter({triangle, {X, Y}, A, B, C}) -> A + B + C.
area({circle, {X, Y}, R}) -> math:pi()*R*R;
area({rectangle, {X, Y}, H, W}) -> H * W;
area({triangle, {X, Y}, H, W}) -> H * W / 2.
enclose({circle, {X, Y}, R}) -> {rectangle, {X,Y}, 2*R, 2*R};
enclose({triangle, {X, Y}, H, W}) -> {rectangle, {X, Y}, H, W}.