Skip to content

Instantly share code, notes, and snippets.

View sgobotta's full-sized avatar
:octocat:

Santiago Botta sgobotta

:octocat:
View GitHub Profile
@sgobotta
sgobotta / hof.erl
Last active May 28, 2020 16:05
Gist for the FeatureLearn Erlang course (4.5) "Higher-order functions in practice"
-module(hof).
-author("@sgobotta").
-include_lib("eunit/include/eunit.hrl").
-export([doubleAll/1, evens/1, product/1]).
-export([zip/2, zip_using_hof/2]).
-export([zip_with/3, zip_with_using_hof/3]).
%% Define the functions doubleAll, evens, and product using the higher-order
%% functions lists:map, lists:filter and lists:foldr.
%%
@sgobotta
sgobotta / bill.erl
Created May 28, 2020 05:04
Gist for the FeatureLearn Erlang course (3.12) "Programming challenge: Supermarket billing"
-module(bill).
-author("@sgobotta").
-export([barcodes/0, main/1]).
-include_lib("eunit/include/eunit.hrl").
-type item_code() :: integer().
-type item_name() :: string().
-type item_price() :: integer().
-type item() :: {item_code(), item_name(), item_price()}.
-type item_maybe() :: nothing | {just, item()}.
@sgobotta
sgobotta / txt.erl
Created May 24, 2020 05:32
Gist for the FeatureLearn Erlang course (3.10) "Programming challenge: Text processing"
-module(txt).
-author("@sgobotta").
-include_lib("eunit/include/eunit.hrl").
-export([
get_file_contents/1,
format/3,
main/2
]).
%% @doc Given a command and a line length, reads the text.txt file to output
@sgobotta
sgobotta / ex.erl
Last active May 18, 2020 07:30
Gist for the FeatureLearn Erlang course (2.19) "Recap: Week 2 so far"
-module(ex).
-author("@sgobotta").
-export([
take/2, test_take/0,
nub/1, test_nub/0,
contains/2, test_contains/0,
palindrome/1, test_palindrome/0
]).
%% @doc Given a number N and a list, takes the first N elements from the list
@sgobotta
sgobotta / list.erl
Created May 17, 2020 19:58
Gist for the FeatureLearn Erlang course (2.18) "Constructing lists with recursive functions"
-module(list).
-author("@sgobotta").
-export([
double_dr/1, test_double_dr/0,
double_tr/1, test_double_tr/0,
evens_dr/1, test_evens_dr/0,
evens_tr/1, test_evens_tr/0,
median/1, test_median/0,
maximum_dr/1, test_maximum_dr/0,
maximum_tr/1, test_maximum_tr/0,
@sgobotta
sgobotta / list.erl
Created May 16, 2020 23:37
Gist for the FeatureLearn Erlang course (2.15) "Defining functions over lists in practice"
-module(list).
-export([
product_dr/1, test_product_dr/0,
product_tr/1, test_product_tr/0,
maximum_dr/1, test_maximum_dr/0,
maximum_tr/1, test_maximum_tr/0
]).
%% @doc Given a list of numbers returns the product of it's elements.
%% The case base should return 1 since it's the neutral element of the
@sgobotta
sgobotta / recursion.erl
Last active May 7, 2020 23:43
Gist for the FeatureLearn Erlang course (2.5) "Tail Recursion"
-module(recursion).
-export([
fib/1,
test_fib/0,
is_perfect_number/1,
test_is_perfect_number/0
]).
fib(N) -> fib(N,0,1).
@sgobotta
sgobotta / recursion.erl
Created May 7, 2020 23:38
Gist for the FeatureLearn Erlang course (2.3)
-module(recursion).
-export([fib/1, fibs/1, pieces/1]).
%% @doc given an integer computes it's position in the fibonacci sequence
fib(0) -> 0;
fib(1) -> 1;
fib(X) -> fib(X-1) + fib(X-2).
%% @doc given a fibonacci sequence position returns the sum of fibonacci computations
fibs(X) -> 1 + 1 + fibs(X-1) + fibs(X-2).
@sgobotta
sgobotta / pattern_matching.erl
Last active May 7, 2020 13:51
Gist for the FeatureLearn Erlang course (1.15)
% @doc Pattern Mathing module for the 1.15 step of the FutureLearn Erlang Course.
-module(pattern_matching).
-export([
xOr/2,
xOr1/2,
xOr2/2,
xOr3/2,
xOr4/2,
max_three/3,
@sgobotta
sgobotta / first.erl
Last active May 5, 2020 22:35
Gists for the FeatureLearn Erlang course (1.9)
-module(first).
-export([
double/1,
mult/2,
area/3,
square/1,
trbl/1,
sum/3
]).