Skip to content

Instantly share code, notes, and snippets.

View danielrhodeswarp's full-sized avatar
💭
Need to research "Gitflow"...

Daniel Rhodes danielrhodeswarp

💭
Need to research "Gitflow"...
  • Greater Manchester, UK
View GitHub Profile
@danielrhodeswarp
danielrhodeswarp / assignment.erl
Created March 5, 2017 08:26
For Future Learn Erlang course assignment 2.20
-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.
@danielrhodeswarp
danielrhodeswarp / one_24.erl
Created February 26, 2017 09:15
For FUNCTIONAL PROGRAMMING IN ERLANG course on FutureLearn.com
-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"),
@danielrhodeswarp
danielrhodeswarp / one_21.erl
Created February 25, 2017 16:48
For FUNCTIONAL PROGRAMMING IN ERLANG course on FutureLearn.com
-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
@danielrhodeswarp
danielrhodeswarp / one_19.erl
Created February 25, 2017 14:10
For FUNCTIONAL PROGRAMMING IN ERLANG course on FutureLearn.com
-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 ================
@danielrhodeswarp
danielrhodeswarp / one_15.erl
Created February 24, 2017 13:13
For FUNCTIONAL PROGRAMMING IN ERLANG course on FutureLearn.com
% 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)
@danielrhodeswarp
danielrhodeswarp / first.erl
Created February 21, 2017 12:34
For FUNCTIONAL PROGRAMMING IN ERLANG course on FutureLearn.com
-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).