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
%% FP in Erlang 3.3 | |
%% | |
%% Programming challenge: indexing a file | |
-module(index). | |
-export( | |
[ get_file_contents/1 | |
, show_file_contents/1 | |
, split_index/2 | |
, split_index_bin/2 |
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
%% More functions over lists | |
%% FP in Erlang 2.27 | |
-module(morefuns). | |
-export( | |
[ join/2 | |
, concat/1 | |
, member/2 | |
, mergesort/1 | |
, quicksort/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
%% FP in Erlang 2.18 | |
%% Constructing lists with recursive functions | |
%% | |
-module(reclists). | |
-export( | |
[ double/1 | |
, even/1 | |
% , divide/4 | |
% , sort/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
%% FP in Erlang 2.15 | |
%% Defining functions over lists in practice | |
-module(funlists). | |
-export( | |
[ product/1 % tail recursive version | |
, product_direct/1 % direct version | |
, maximum/1 % tail recursive version | |
, maximum_direct/1 % direct version | |
, maximum_brujo/1 % both direct and tail recursive |
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
%% @doc Tail recursion - FP in Erlang 2.5 | |
-module(tail). | |
-export([sum/2, maximum/2, fib/1, perfect/1, test/0]). | |
%% @doc Given a function (Fun: int -> int) and an integer N, | |
%% find the value of Fun(N) + Fun(N - 1) + ... + Fun(0). | |
%% | |
%% sum_aux is auxiliary function keeping a current Sum value |
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
%% @doc Recursion examples - FP in Erlang 2.3 | |
-module(recursion). | |
-export([fib/1, pieces/1, test/0]). | |
%% @doc Give N-th element of Fibonacci sequence | |
fib(0) -> 0; | |
fib(1) -> 1; | |
fib(N) when N > 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
%% @doc Practice patterns (1.15) | |
-module(patterns). | |
-export([x_or_1/2, x_or_2/2, x_or_3/2, max/2, max_three/3, how_many_equal/3, test/0]). | |
%% @doc Give three "exclusive ors" | |
x_or_1(X, Y) -> | |
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
%% @doc Functions for calculating perimeter and area of a right angled triangle | |
-module(second). | |
-export([hypotenuse/2, perimeter/2, area/2]). | |
hypotenuse(A, B) -> | |
math:sqrt(first:square(A) + first:square(B)). | |
%% @doc Perimeter of a right angled triangle | |
%% A, B - lengths of shorter sides |
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
%% @doc Function for calculating area of any triangle and some auxiliary | |
%% functions | |
-module(first). | |
-export([area/3, double/1, mult/2, square/1, treble/1]). | |
mult(X, Y) -> | |
X * Y. | |
double(X) -> |