Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erlang Path #1

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6e56885
Initial version of bob assignment.
tmcgilchrist Aug 30, 2013
65b41d4
All tests passing.
robinhilliard Oct 2, 2013
05a5823
Take one down -> Take it down according to the instructions
robinhilliard Oct 2, 2013
42f4a3f
Rename beer_song.erl to example.erl to match exercism format
robinhilliard Oct 2, 2013
5c43b39
Remove unintended module name refactor in code
robinhilliard Oct 2, 2013
b69d03e
Tests passing
robinhilliard Oct 2, 2013
8c3b259
Initial commit
robinhilliard Oct 4, 2013
cee6a9d
Tests passing
robinhilliard Oct 4, 2013
f1ce558
Rename anagram.erl to example.erl
robinhilliard Oct 4, 2013
39853de
Initial commit
robinhilliard Oct 4, 2013
cc20b66
Simple test passing, expecting trailing \n
robinhilliard Oct 8, 2013
e218e33
Renamed to example.erl
robinhilliard Oct 8, 2013
5f3e73d
Added a more idiomatic example using dict that doesn't preserve word …
robinhilliard Oct 8, 2013
011f02d
Of course now we don't need lists:reverse
robinhilliard Oct 8, 2013
d4da545
Initial commit
robinhilliard Oct 9, 2013
75f74ee
Tests passing
robinhilliard Oct 9, 2013
c5b5fa5
Rename dna.erl to example.erl
robinhilliard Oct 9, 2013
fc2c70b
Flatten input
robinhilliard Oct 9, 2013
2e3358b
Add white space
robinhilliard Oct 9, 2013
359fc03
Add allergies example.
tmcgilchrist Oct 10, 2013
a4920ff
Mark phone-number as in progress.
tmcgilchrist Oct 11, 2013
bbf5901
Add etl example.
milo-hyben Oct 14, 2013
c8d6220
Add etl example.
milo-hyben Oct 14, 2013
0989889
Add etl example.
milo-hyben Oct 14, 2013
64cf418
Initial version of the phone number exercise.
tmcgilchrist Oct 18, 2013
2230fa6
Finished nucleotide exercise.
tmcgilchrist Oct 22, 2013
d9afdaa
Mark point-mutation as in progress.
tmcgilchrist Oct 23, 2013
121dde2
Add hamming distance tests.
tmcgilchrist Oct 28, 2013
86c863e
Working point mutations example.
tmcgilchrist Oct 28, 2013
aca9247
Rename to example.
tmcgilchrist Oct 28, 2013
b80de9c
Instructions for running the erlang tests.
tmcgilchrist Oct 28, 2013
b19f27f
Update curriculum to currently finished examples.
tmcgilchrist Oct 28, 2013
c2523e7
Merge remote-tracking branch 'etrepum/erlang' into erlang
tmcgilchrist Feb 5, 2014
54bba4c
Finish grade school example using orddict.
tmcgilchrist Feb 10, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assignments/erlang/anagram/example.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(anagram).
-module(example).
-export([find/2]).

-spec find(string(), [string()]) -> [string()].
Expand Down
43 changes: 43 additions & 0 deletions assignments/erlang/bob/bob_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-module(bob_tests).

-include_lib("eunit/include/eunit.hrl").

responds_to_something_test() ->
bob_responds("Tom-ay-to, tom-aaaah-to.", "Whatever.").

responds_to_shouts_test() ->
bob_responds("WATCH OUT!", "Woah, chill out!").

responds_to_questions_test() ->
bob_responds("Does this cryogenic chamber make me look fat?", "Sure.").

responds_to_forceful_talking_test() ->
bob_responds("Let's go make out behind the gym!", "Whatever.").

responds_to_acronyms_test() ->
bob_responds("It's OK if you don't want to go to the DMV.", "Whatever.").

responds_to_forceful_questions_test() ->
bob_responds("WHAT THE HELL WERE YOU THINKING?", "Woah, chill out!").

responds_to_shouting_with_special_characters_test() ->
bob_responds("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!", "Woah, chill out!").

responds_to_shouting_numbers_test() ->
bob_responds("1, 2, 3, GO!", "Woah, chill out!").

responds_to_shouting_with_no_exclamation_mark_test() ->
bob_responds("I HATE YOU", "Woah, chill out!").

responds_to_statement_containing_question_mark_test() ->
bob_responds("Ending with ? means a question", "Whatever.").

responds_to_silence_test() ->
bob_responds("", "Fine. Be that way.").

responds_to_prolonged_silence_test() ->
bob_responds(" ", "Fine. Be that way.").

bob_responds(Question, Answer) ->
?assertEqual(bob:response_for(Question),
Answer).
23 changes: 23 additions & 0 deletions assignments/erlang/grade-school/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-module(grade_school).

-export([add/3, get/2, sort/1]).

-spec add(string(), integer(), dict()) -> dict().
add(Name, Grade, Students) ->
case orddict:find(Grade, Students) of
{ok, Class} ->
orddict:store(Grade, lists:sort([Name | Class]), Students);
error ->
orddict:store(Grade, [Name], Students)
end.

-spec get(integer(), dict()) -> [string()].
get(Grade, Students) ->
case orddict:find(Grade, Students) of
{ok, Class} -> Class;
_ -> []
end.

-spec sort(dict()) -> dict().
sort(S) ->
S.
48 changes: 48 additions & 0 deletions assignments/erlang/grade-school/grade_school_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
% To run tests:
% elc *.erl
% erl -noshell -eval "eunit:test(grade_school), [verbose])" -s init stop
%

% use a dict with keys for each grade and a list of the students within that grade.
% [{'grade-1', ['bill']}, {'grade-2', ['george', 'fred']]
-module(grade_school_tests).

-include_lib("eunit/include/eunit.hrl").

%% Using proplists
add_student_test() ->
?assertEqual(grade_school:add("Aimee", 2, []),
[{2, ["Aimee"]}]
).

add_more_students_in_same_class_test() ->
S1 = grade_school:add("James", 2, []),
S2 = grade_school:add("Blair", 2, S1),
S3 = grade_school:add("Paul", 2, S2),
?assertEqual(S3, [{2, ["Blair","James","Paul"]}]).

add_students_to_different_grades_test() ->
S1 = grade_school:add("Chelsea", 3, []),
S2 = grade_school:add("Logan", 7, S1),
?assertEqual(S2, [{3, ["Chelsea"]}, {7, ["Logan"]}]).

get_students_in_a_grade_test() ->
S1 = grade_school:add("Franklin", 5, []),
S2 = grade_school:add("Bradley", 5, S1),
S3 = grade_school:add("Jeff", 1, S2),
?assertEqual(grade_school:get(5, S3), ["Bradley","Franklin"]).

get_students_in_a_non_existant_grade_test() ->
?assertEqual([], grade_school:get(1, [])).

sort_school_test() ->
S1 = grade_school:add("Jennifer", 4, []),
S2 = grade_school:add("Kareem", 6, S1),
S3 = grade_school:add("Christopher", 4, S2),
S4 = grade_school:add("Kyle", 3, S3),

Sorted = [{3, ["Kyle"]},
{4, ["Christopher", "Jennifer"]},
{6, ["Kareem"]}],

?assertEqual(Sorted, grade_school:sort(S4)).
28 changes: 28 additions & 0 deletions assignments/erlang/point-mutations/dna_tests.erl
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
-module(dna_tests).

-include_lib("eunit/include/eunit.hrl").

no_difference_between_empty_strands_test() ->
?assertEqual(dna:hamming_distance("", ""), 0).

no_dofference_between_identical_strands_test() ->
?assertEqual(dna:hamming_distance("GGACTGA", "GGACTGA"), 0).

complete_hamming_distance_in_small_strang_test() ->
?assertEqual(dna:hamming_distance("ACT", "GGA"), 3).

hamming_distance_in_off_by_one_strand_test() ->
?assertEqual(dna:hamming_distance("GGACGGATTCTGACCTGGACTAATTTTGGGG",
"AGGACGGATTCTGACCTGGACTAATTTTGGGG"), 19).

small_hamming_distance_in_middle_somewhere_test() ->
?assertEqual(dna:hamming_distance("GGACG", "GGTCG"), 1).

larger_distance_test() ->
?assertEqual(dna:hamming_distance("ACCAGGG", "ACTATGG"), 2).

ignores_extra_length_on_other_strand_when_longer_test() ->
?assertEqual(dna:hamming_distance("GACTACGGACAGGGTAGGGAAT", "GACATCGCACACC"), 5).

does_not_actually_shorten_original_strand_test() ->
?assertEqual(dna:hamming_distance("AGACAACAGCCAGCCGCCGGATT", "AGGCAA"), 1),
?assertEqual(dna:hamming_distance("AGACAACAGCCAGCCGCCGGATT", "AGGCAA"), 1),
?assertEqual(dna:hamming_distance("AGACAACAGCCAGCCGCCGGATT", "AGACATCTTTCAGCCGCCGGATTAGGCAA"), 4),
?assertEqual(dna:hamming_distance("AGACAACAGCCAGCCGCCGGATT", "AGG"), 1).
15 changes: 15 additions & 0 deletions assignments/erlang/point-mutations/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-module(dna).

-export([hamming_distance/2]).

hamming_distance(From, To) ->
% Make both lists the same length, as zipwith expects them to be.
ToPrime = lists:sublist(To, length(From)),
FromPrime = lists:sublist(From, length(To)),
Comparisons = lists:zipwith(fun(X,Y) -> case X =:= Y of
true -> 0;
false -> 1
end
end,
FromPrime, ToPrime),
lists:sum(Comparisons).
17 changes: 17 additions & 0 deletions assignments/erlang/word-count/example2.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-module(word_count).
-export([count/1]).



count(WordList) when is_list(WordList)->
count(string:tokens(lists:flatten(WordList), " "), dict:new()).



%% Alternative shorter implementation using dict that doesn't preserve key order

count([], Tally) ->
lists:flatten([io_lib:format("~s: ~B\n", [Word, Count]) || {Word, Count} <- dict:to_list(Tally)]);

count([Word|Words], Tally) ->
count(Words, dict:update(Word, fun(Count) -> Count + 1 end, 1, Tally)).
11 changes: 11 additions & 0 deletions lib/app/views/setup/erlang.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h3>Erlang</h3>

<h4>Installation: </h4>

<p>
Download and install a recent Erlang/OTP release for your OS from
<a href="http://www.erlang.org/download.html">erlang.org</a>.
</p>

<h4>Building and running tests: </h4>
<pre>$ erl -make && erl -noshell -eval 'init:stop(case bob_tests:test() of ok -> 0; _ -> 1 end).'</pre>
4 changes: 2 additions & 2 deletions lib/exercism/curriculum/erlang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class ErlangCurriculum
def slugs
%w(
bob rna-transcription word-count anagram beer-song
nucleotide-count point-mutations phone-number grade-school
)
# nucleotide-count point-mutations phone-number
# grade-school robot-name leap etl meetup space-age grains
# robot-name leap etl meetup space-age grains
# gigasecond triangle scrabble-score roman-numerals
# binary prime-factors raindrops allergies
# atbash-cipher
Expand Down