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(rps2). | |
-export([play/1,echo/1,play_two/3,rock/1,no_repeat/1,const/1,enum/1,cycle/1,rand/1,val/1,tournament/2]). | |
% | |
% play one strategy against another, for N moves. | |
% | |
play_two(StrategyL,StrategyR,N) -> | |
play_two(StrategyL,StrategyR,[],[],N). |
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(rps). | |
-export([result/2]). | |
-export([tournament/2]). | |
% Win and Lose | |
beat(rock) -> paper; | |
beat(paper) -> scissors; | |
beat(scissors) -> rock. | |
lose(rock) -> scissors; |
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(hofs). | |
-export([doubleAll/1]). | |
-export([evens/1]). | |
-export([product/1]). | |
-export([zip/2]). | |
-export([zip2/2]). | |
-export([zip_with/3]). | |
-export([zip_with2/3]). | |
% Using higher-order functions |
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). | |
-export([get_file_contents/1,show_file_contents/1]). | |
-export([wordindex/1, test/1]). | |
% | |
% Indexing a file | |
% Given a text file, return a list of words and the ranges of lines on which it occurs | |
% | |
-spec wordindex(string()) -> [{string(), [{integer(),integer()}]}]. |
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(consolidation). | |
-export([join/2, join_test/0]). | |
-export([concat/1, concat_test/0]). | |
-export([member/2]). | |
% Joining Lists | |
% | |
% My implementation of ++ called join/2 (which uses shunt from previous modules) | |
-spec join([T], [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(palindrome). | |
-export([palindrome/1, clean/1, clean/2, palindrome_test/0]). | |
% palindrome("Madam I\'m Adam") = true | |
palindrome([]) -> []; | |
palindrome(List) -> | |
CleanList = clean(List), | |
ReversedList = lists:reverse(CleanList), |
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(dedupe2). | |
-export([exists/2,nubfb/1,nubfb/2,nubbf/1,nubbf/2,nub_test/0]). | |
% nubfb([2,4,1,3,3,1]) = [2,4,1,3] | |
% nubbf([2,4,1,3,3,1]) = [2,4,3,1] | |
exists(Val, []) -> [Val]; | |
exists(Val, [X|_Xs]) when Val == X -> []; | |
exists(Val, [X|Xs]) when Val =/= X -> exists(Val, Xs). |
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(dedupe). | |
-export([exists/2,nubfb/1,nubfb/2,nubbf/1,nubbf/2,nub_test/0]). | |
% nubfb([2,4,1,3,3,1]) = [2,4,1,3] | |
% nubbf([2,4,1,3,3,1]) = [2,4,3,1] | |
exists(_, []) -> false; | |
exists(Val, [X|_Xs]) when Val == X -> true; | |
exists(Val, [X|Xs]) when Val =/= X -> exists(Val, Xs). |
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, take_test/0]). | |
-spec take(integer(), [T]) -> [T]. | |
take(0, _) -> []; | |
take(_, []) -> []; | |
take(Cnt, [X|Xs]) when Cnt > 0 -> [X | take(Cnt-1, Xs)]. | |
take_test() -> | |
[] = take(0,"hello"), |
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(listcons). | |
-export([double/1]). | |
-export([doubleelems/1]). | |
-export([even/1,evens/1]). | |
% Erlang Course activity 2.9 | |
% Transforming List Elements | |
% Define an Erlang function double/1 to double the elements of a list of numbers. |