Skip to content

Instantly share code, notes, and snippets.

@Joakineee
Joakineee / mailbox.erl
Created July 6, 2020 15:28
testing the mailbox
-module(mailbox).
-export([start/0,proccess/0,proccess2/0]).
start() ->
spawn(mailbox,proccess,[]).
proccess() ->
timer:sleep(3000),
receive
stop -> ok;
@Joakineee
Joakineee / palindrome.erl
Last active July 6, 2020 11:37
basic palindrome exercise
-module(palindrome).
-export([server/1]).
rem_punct(String) -> lists:filter(fun (Ch) ->
not(lists:member(Ch,"\"\'\t\n "))
end,
String).
@Joakineee
Joakineee / rps.erl
Created June 11, 2020 13:09
rock papper scissor
-module(rps).
-export([tournament/2]).
beat(rock) -> paper;
beat(paper) -> scissors;
beat(scissors) -> rock.
result({X,X},Acc) -> Acc;
@Joakineee
Joakineee / format.erl
Created May 27, 2020 08:43
text_processing exercise.
-module(format).
-export([text_processing/3]).
% 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.
% Each line has its trailing newline removed.
@Joakineee
Joakineee / index.erl
Created May 25, 2020 08:53
index file exercice
-module(index).
-export([get_file_contents/1,show_file_contents/1,index_words/1,test/0]).
% 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.
% Each line has its trailing newline removed.
@Joakineee
Joakineee / nub.erl
Created May 15, 2020 12:47
Erlang exercise nub
-module(nub).
-export([test/0,nub/1]).
-spec nub(list()) -> list().
nub(L) -> nub(L,[]).
%Adds non repeated elements to the list.
-spec nub(list(),list()) -> list().
@Joakineee
Joakineee / take.erl
Created May 15, 2020 12:21
erlang exercise take.
-module(take).
-export([take/2]).
-spec take(integer(),list()) -> list().
take(X,L) -> take(X,L,[]).
-spec take(integer(),list(),list()) -> list().
take(_,[],Acc) -> lists:reverse(Acc);
take(0,_,Acc) -> lists:reverse(Acc);
@Joakineee
Joakineee / constructing_lists.erl
Created May 15, 2020 10:57
exerciese create list
-module(constructing_lists).
-export([double/1,evens/1,test/0,median/1,modes/1]).
%double function start here.
double(L) -> double(L,[]).
double([],Acc) ->
reverse(Acc,[]);
double([H|T],Acc) ->
@Joakineee
Joakineee / w2lists.erl
Last active May 16, 2020 09:37
Tail recursive lists
-module(w2lists).
-export([prod/1,mymax/1,test/0]).
%Moddified according Elbrujohalcon:
%Removed the "list is emty" function clause as we will let it crash.
%prod([]) ->
% "list is empty";
prod([H|T]) ->
prod(T,H).
@Joakineee
Joakineee / pat.erl
Created May 14, 2020 07:48
Put all in toguether1
-module(pat).
-export([perimeter/1,area/1,enclosure/1,bits/1,bits_rec/1,tests/0]).
%Shapes exercises
%I considered not necessary to validate the shapes as john don't use it during his examples,
% forexp in circle R > 0 and in triangle A + B > C,etc..
perimeter({circle,_,Radius}) ->
2 * math:pi() * Radius;