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]). | |
%-export([mult / 2]). | |
-export([area / 3, square / 1, treble / 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
% valid module name | |
-module(one_15). | |
-export([x_or_1 / 2, x_or_2 / 2, x_or_3 / 2]). | |
-export([x_or_4 / 2, x_or_5 / 2, x_or_6 / 2]). | |
-export([maxThree / 3]). | |
-export([howManyEqual / 3]). | |
% ==== EXCLUSIVE OR ================ | |
% first method (from vid) |
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(one_19). | |
-export([fac / 1, test / 1, getFromList / 1, getLastTwo / 1, fib / 1]). | |
fac(0) -> | |
1; | |
fac(N) when N > 0 -> | |
fac(N - 1) * N. | |
% ==== FIBONACCI NUMBERS ================ |
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(one_21). | |
-export([fib / 1, newFib / 1]). | |
% from lesson 1.20 ("is exponentially complex … ouch!") | |
fib(0) -> 0; | |
fib(1) -> 1; | |
fib(N) -> fib(N - 2) + fib(N - 1). | |
% "Define an efficient Fibonacci function fib/3 using | |
% a tail recursion with two accumulating parameters |
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(one_24). | |
-export([perimeter / 1, area / 1, enclose / 1]). % shapes | |
-export([bits / 1]). % summing the bits | |
-export([testAll / 0, testArea / 0, testPerimeter / 0, testEnclose / 0, testBits / 0]). % tests for shapes AND bits | |
% ==== MASTER TESTER ================ | |
% run all automated tests (and return "has everything passed?" boolean) | |
testAll() -> | |
io:format("Running all tests~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(assignment). | |
-export([checkFile/1, indexFile/1, tokeniseLine/1]). | |
-export([addToWordTuple/2, wordInWordTupleList/2]). | |
-export([rangifyList/1]). | |
% NOTE you'll need to compile index.erl in the Erlang shell first! | |
% then compile this and run assignment:indexFile("gettysburg-address.txt"). or what-have-you | |
% Indexing a file | |
% The aim of this exercise is to index a text file, by line number. |