Skip to content

Instantly share code, notes, and snippets.

View pppillai's full-sized avatar

Pradeep Prabhakaran Pillai pppillai

View GitHub Profile
-module(tailrecursion).
-export([loop/1, fib/1, perfect/1, test_perfect_number/0, test_fib/0]).
loop(N) when N > 0 ->
io:format("~p~n", [N]),
loop(N-1);
loop(_N) ->
io:format("bye ~n").
-module(week2_perfect_number).
-export([perfectNumber/1]).
-author("Pradeep Pillai").
perfectNumber(N) ->
A = doPerfect(N, N div 2, []),
N == lists:sum(A).
doPerfect(_, 0, Result) ->
-module(fibandcuts).
-export([factorial/1, fibonacci/1, pieces/1]).
-export([test_pieces/0,test_fibonacci/0]).
-author("Pradeep Pillai").
%Factorial of N
%1 * 2 * 3 * (N-1)
%Factorial of 0 is 0
-module(week1).
-export([xOr_first_impl/2, xOr_second_impl/2, xOr_third_impl/2, maxThree/3, howManyEqual/3
, test_howManyEqual_function/0, test_maxThree_function/0, test_xOrImpl_function/0]).
%xOr implementations.
xOr_first_impl(A, B) ->
A =/= B.
-module(second).
-import(first, [squareValue/1]).
-export([sizeOfHypotenuse/2, perimeterOfRightAngledTriangle/2, areaOfTriangle/2]).
%%below functions to be used for right angled triangle
%returns the hypotenuse
sizeOfHypotenuse(SideOne, SideTwo) ->
math:sqrt(squareValue(SideOne) + squareValue(SideTwo)).
-module(first).
-export([double/1, mult/2, area/3, squareValue/1, tripleValue/1]).
mult(X, Y) ->
X * Y.
double(X) ->
mult(X, 2).