Skip to content

Instantly share code, notes, and snippets.

@jo1077
jo1077 / index.erl
Created May 18, 2020 02:35 — forked from charithe/index.erl
FutureLearn Erlang MOOC Week 2: Indexing a file
-module(index).
-export([do_index/1, show_file_contents/1]).
%% Main entrypoint
%% In the Erlang shell, execute: rp(index:do_index("path_to_file")).
%% Reads the contents of the file using the provided functions, builds up a map
%% of words to their locations, compresses the locations to ranges and returns a
%% list sorted in alphabetical order
do_index(Name) ->
Lines = get_file_contents(Name),
@jo1077
jo1077 / index.erl
Created May 18, 2020 00:25 — forked from einarwh/index.erl
Functional programming in Erlang. Programming challenge: indexing a file.
-module(index).
-export([get_file_contents/1,show_file_contents/1,run/1,just_words/1,print_words/1]).
% Self reference! View this gist at https://gist.github.com/einarwh/7c287097f54f549a427a537ec0caee47
% This solution should produce output roughly as specified.
% Short words are dropped, the words are sorted, and all words are in lowercase form.
% I haven't attempted to "canonicalize" words any further (singulars and plurals are distinct).
% For faster lookup, a dictionary (dict in Erlang, apparently) might have been useful.
@jo1077
jo1077 / second_week.erl
Created May 17, 2020 03:08 — forked from Acentelles/second_week.erl
Second week - Index a file - FUNCTIONAL PROGRAMMING IN ERLANG - THE UNIVERSITY OF KENT
-module(index).
-export([get_file_contents/1,show_file_contents/1, find_index/2]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
% Get the contents of a text file into a list of lines.
@jo1077
jo1077 / index.erl
Created May 17, 2020 03:05 — forked from rui-dias/index.erl
Functional Programming in Erlang - Programming challenge: indexing a file
-module(index).
-include_lib("eunit/include/eunit.hrl").
-export([get_file_contents/1,show_file_contents/1,main/1]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
@jo1077
jo1077 / index.erl
Created May 17, 2020 02:52 — forked from ekalinin/index.erl
indexing a file
-module(index).
-compile([export_all]).
% -export([get_file_contents/1,show_file_contents/1]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
@jo1077
jo1077 / index.erl
Created May 15, 2020 03:32 — forked from emaphis/index.erl
Functional programming in Erlang -- index program.
-module(index).
-export([get_file_contents/1,show_file_contents/1]).
-export([index_file/1,print_index/1]).
-export([partition_test/0]).
%% The main prorgram.
%% Run:
%% index:index_file("gettysburg-address.txt").
%% to produce a list of word indexes.
@jo1077
jo1077 / index.erl
Created May 14, 2020 03:40 — forked from colinbankier/index.erl
Indexing a file - Erlang
-module(index).
-export([get_index/1]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
% Get the contents of a text file into a list of lines.
-module(lists2).
-export([join/2,concat/1,member/2,sort/1,sort/2,perms/1]).
-export([join_test/0,concat_test/0,member_test/0,sort_test/0,perms_test/0]).
%% Join %%%
join(L1, L2) when is_list(L1), is_list(L2) ->
join_internal(lists:reverse(L1), L2).
join_internal(L1, []) -> lists:reverse(L1);
join_internal(L1, [H|T]) ->
@jo1077
jo1077 / morelists.erl
Created May 14, 2020 02:47 — forked from dduugg/morelists.erl
Functional Programming in Erlang: 2.27
-module(morelists).
-export([concat/1, concat_test/0, insertion_sort/1,
join/2, join_test/0, member/2, member_test/0,
merge_sort/1, perms/1, perms_test/0, quicksort/1,
sort_tests/0]).
join([], Y) -> Y;
join([X | Xs], Y) -> [X | join(Xs, Y)].
@jo1077
jo1077 / ass_wk1.erl
Created May 11, 2020 03:08 — forked from duncanatt/ass_wk1.erl
Functional Programming in Erlang - Week 1 Assignment
-module (ass_wk1).
-export ([area/1, perimeter/1, enclose/1, bits/1, bits_tail/1]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Question 1 - Shapes. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% I'm assuming three shapes: circles, rectangles and squares.
%% Perimeter of circle is calulated using the standard formula 2 * Pi * R.