This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(second). | |
-export([hypotenuse/2,perimeter/2,area/2]). | |
hypotenuse(X,Y) -> | |
math:sqrt(first:square(X) + first:square(Y)). | |
perimeter(X,Y) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(first). | |
-export([double/1,mult/2,area/3,square/1,treble/1]). | |
mult(X,Y) -> | |
X*Y. | |
double(X) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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 -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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(). |
OlderNewer