This file contains 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, squareValue/1, tripleValue/1]). | |
mult(X, Y) -> | |
X * Y. | |
double(X) -> | |
mult(X, 2). |
This file contains 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). | |
-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)). |
This file contains 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(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. |
This file contains 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(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 |
This file contains 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(week2_perfect_number). | |
-export([perfectNumber/1]). | |
-author("Pradeep Pillai"). | |
perfectNumber(N) -> | |
A = doPerfect(N, N div 2, []), | |
N == lists:sum(A). | |
doPerfect(_, 0, Result) -> |
This file contains 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(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"). |
This file contains 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(four_arg_fib). | |
-export([fib/1, test_fib/0]). | |
%four argument fib function | |
fib(N) -> | |
fib(0, 0, 1, N). | |
fib(From, Current, _Next, From) -> | |
Current; | |
fib(From, Current, Next, To) -> | |
fib(From+1, Next, Current + Next, To). |
This file contains 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('chapter-5'). | |
-export([map_search_pred/2]). | |
% write a funciton map_search(Map, Pred) that returns the first element {Key, Value} | |
% in the map for which Pred(Key, Value) is true. | |
% 16> A = fun(X, Y) -> case X > Y of true -> true; _ -> false end end. | |
% #Fun<erl_eval.13.126501267> | |
% 17> A(1, 2). | |
% false | |
% 18> 'chapter-5':map_search_pred(#{1=>2, 4=>3}, A). |
This file contains 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(countchar). | |
-export([count_characters/1]). | |
count_characters(Str) -> | |
count_characters(Str, #{}). | |
count_characters([], Result) -> | |
Result; | |
count_characters([H|T], Result) -> | |
case maps:is_key(H, Result) of |
This file contains 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, test_take/0]). | |
% Define a function take that takes the first N elements from a list. Here are some examples of take in action: | |
% take(0,"hello") = [] | |
% take(4,"hello") = "hell" | |
% take(5,"hello") = "hello" | |
% take(9,"hello") = "hello" | |
-spec take(non_neg_integer(), [T]) -> [T]. |
OlderNewer