This file contains hidden or 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). | |
-compile([export_all]). | |
-export([index_text/1]). | |
-define(MINLENGTH, 8). | |
-include_lib("eunit/include/eunit.hrl"). | |
%% to run c(index). | |
%% index:index_text("FullPathOfFile"). | |
% Used to read a file into a list of lines. |
This file contains hidden or 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(week227). | |
-compile([export_all]). | |
-include_lib("eunit/include/eunit.hrl"). | |
join(Xs, Ys) -> | |
accumulate(shunt(Xs, []), Ys). | |
shunt([], Ys) -> | |
Ys; |
This file contains hidden or 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(palindorme). | |
-export([palindrome/1]). | |
palindrome(Name) -> | |
Name==palindrome(Name, []). | |
palindrome([], Result) -> | |
Result; | |
palindrome([H|T], Result) -> |
This file contains hidden or 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(week218). | |
-export([test/0]). | |
% -compile(export_all). | |
-include_lib("eunit/include/eunit.hrl"). | |
test() -> | |
?assertEqual((double([])), []), | |
?assertEqual((double([1, 2])), [1, 4]), | |
?assertEqual((evens([4, 6, 7, 8])), [4, 6, 8]), | |
?assertEqual((evens([])), []), |
This file contains hidden or 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(week215). | |
-export([maximum/1, product/1, test/0]). | |
-include_lib("eunit/include/eunit.hrl"). | |
% Combining list elements: the product of a list | |
% Using the template from the last session, 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: why? | |
%% because List is either a term or/and an empty list | |
%% and zero * anything is zero. |
This file contains hidden or 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(assignment1). | |
-include_lib("eunit/include/eunit.hrl"). | |
-export([perimeter/1, area/1, enclose/1, bits/1, bits/2, test/0]). | |
%% compile:file(assignment1, [debug_info, export_all, {outdir, beam}]). | |
%% assignment1.erl is module and beam is dir. | |
%% Shapes | |
%% Define a function perimeter/1 which takes a shape and returns the perimeter of the shape. | |
perimeter({triangle, {A, B, C}}) -> |
This file contains hidden or 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(take). | |
-export([take/2, test_take/0]). | |
% Define a function take that takes the first N elements from a list. Here are some examples of take in action: | |
% take(0,"hello") = [] | |
% take(4,"hello") = "hell" | |
% take(5,"hello") = "hello" | |
% take(9,"hello") = "hello" | |
-spec take(non_neg_integer(), [T]) -> [T]. |
This file contains hidden or 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(countchar). | |
-export([count_characters/1]). | |
count_characters(Str) -> | |
count_characters(Str, #{}). | |
count_characters([], Result) -> | |
Result; | |
count_characters([H|T], Result) -> | |
case maps:is_key(H, Result) of |
This file contains hidden or 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('chapter-5'). | |
-export([map_search_pred/2]). | |
% write a funciton map_search(Map, Pred) that returns the first element {Key, Value} | |
% in the map for which Pred(Key, Value) is true. | |
% 16> A = fun(X, Y) -> case X > Y of true -> true; _ -> false end end. | |
% #Fun<erl_eval.13.126501267> | |
% 17> A(1, 2). | |
% false | |
% 18> 'chapter-5':map_search_pred(#{1=>2, 4=>3}, A). |
This file contains hidden or 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(four_arg_fib). | |
-export([fib/1, test_fib/0]). | |
%four argument fib function | |
fib(N) -> | |
fib(0, 0, 1, N). | |
fib(From, Current, _Next, From) -> | |
Current; | |
fib(From, Current, Next, To) -> | |
fib(From+1, Next, Current + Next, To). |
NewerOlder