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
% Marcelo Ruiz-Camauër | |
% Introduction to Erlang assignment 1.24 | |
% Feb. 2017 | |
% | |
% Shapes: | |
% Define a function perimeter/1 which takes a shape and returns the perimeter of the shape. | |
% Choose a suitable representation of triangles, and augment area/1 and perimeter/1 to handle this case too. | |
% Define a function enclose/1 that takes a shape an returns the smallest enclosing rectangle of the shape. | |
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
% Marcelo Ruiz Camauër | |
% assignment 2.6 | |
-module(a26). | |
-export([listprod/1,listprod2/1,listmax/1,listmax2/1]). | |
% define an Erlang function to give the product of a list of numbers. | |
% The product of an empty list is usually taken to be 1 | |
% recursive listprod(): |
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
% Marcelo Ruiz Camauër | |
% assignment 2.6 a26_tests | |
% invoke with 'a26_tests:test().' | |
-module(a26_tests). | |
-include_lib("eunit/include/eunit.hrl"). | |
listprod_test()-> | |
?assertEqual(1,a26:listprod([])), |
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
% Marcelo Ruiz Camauër | |
% assignment 2.9 | |
-module(a29). | |
-export([double/1,evens/1, median/1]). | |
-include_lib("eunit/include/eunit.hrl"). | |
%Define an Erlang function double/1 to double the elements of a list of numbers | |
double([])->[]; | |
double(L) -> [Value * 2 || Value <- L]. |
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
% Marcelo Ruiz Camauër | |
% assignment 2.11 | |
% Define a function take that takes the first N elements from a list. | |
-module(a211). | |
-export([take/2]). | |
-include_lib("eunit/include/eunit.hrl"). | |
-spec take(integer(),[L]) -> [L]. |
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
%%% assignment 2.13 | |
-module(a213). | |
-include_lib("eunit/include/eunit.hrl"). | |
-created_by("Marcelo Ruiz Camauër"). | |
-export([nub/1]). | |
%% contains() copied from Jeremiah B.: | |
contains([], _Y) -> |
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
%%% assignment 2.15 palindromes | |
-module(a215). | |
-include_lib("eunit/include/eunit.hrl"). | |
-created_by("Marcelo Ruiz Camauër"). | |
-export([palindrome/1]). | |
-export([remove_punctuation/2]). | |
-spec palindrome(list()) -> boolean(). |
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
%%% assignment 2.20 | |
% Indexing a file | |
% The aim of this exercise is to index a text file, by line number. | |
% We can think of the input being a list of text strings, and below we’ve provided an outline Erlang | |
% module that reads text files into this format, as well as a couple of example files to process. | |
% The output of the main function should be a list of entries consisting of a word | |
% and a list of the ranges of lines on which it occurs. | |
% | |
% For example, the entry |
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(index). | |
-export([index_file/1]). | |
readlines(Name) -> | |
{ok,File} = file:open(Name,[read]), | |
extract_content(File,[]). | |
extract_content(File,Partial) -> | |
case io:get_line(File,"") of | |
eof -> file:close(File), Partial; |
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(a35). | |
-export([doubleAll/1, evens/1, product/1,zip/2,zip_with/3,zip_with_map/3,zip_with_zip_with/2]). | |
-include_lib("eunit/include/eunit.hrl"). | |
-created_by("Marcelo Ruiz Camauër"). | |
%%% invoke with: | |
%%% a35:test(). | |
%%% higher order functions |
OlderNewer