Skip to content

Instantly share code, notes, and snippets.

@7-fl
7-fl / f2.erl
Created April 11, 2017 13:51
Week1/Assignment1
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(f2).
-export([start/0,allocate/0,deallocate/1,stop/0]).
@7-fl
7-fl / freq.erl
Last active April 9, 2017 01:51
Week1/Modify frequency server
-module(freq).
-export([loop/1, init/0, start/0, deallocate/2]).
-include_lib("eunit/include/eunit.hrl").
start() ->
register(freq, spawn(freq, init, [])).
get_freqs() ->
[10,11,12,13,14].
@7-fl
7-fl / w1.erl
Last active April 5, 2017 09:09
-module(w1).
-export([server1/1, server2/0, client/1, front_end/0, loop/3]).
%Palindrome server for a single client:
server1(Pid) ->
receive
{check, Str} ->
Result = case palin:palindrome(Str) of
true -> " is ";
false -> " is not "
@7-fl
7-fl / rps.erl
Last active March 22, 2017 17:06
Finished! + After the fact, I was able to implement more comprehensive testing.
-module(rps).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
%
% play one strategy against another, for N moves.
%
play_two(S1, S2, N) ->
play_two(S1, S2, N, [], [], 0). %Added 0 variable to sum the score.
@7-fl
7-fl / comments.md
Last active May 7, 2017 03:38
What do you think about Erlang?

What is most difficult about learning Erlang? (And what’s easiest?)

Difficult: Recursion, Reading other people’s code.
For some problems, I find it exceedingly difficult--and sometimes I’m unable--to figure out a recursive, stateless solution. That kind of shakes my confidence. While for other problems, I can quickly envision a solution, and I start writing code immediately.

When the solutions got more complex, it was tough to debug my own code--much less somebody else’s, so I found it hard to review other people’s code--even though I was already intimately aware of the issues involved in solving the problem. Judicious commenting helped. Tests helped. Then if things were still unclear, digging in and manually following the function execution with some real values helped. If I hadn’t already solved the problem first, I doubt I would have been able to decipher what the heck was going on. I think it would be really hard to revisit someone else’s solution in six months and try to understand

@7-fl
7-fl / rps.erl
Last active March 13, 2017 09:26
Finished!
-module(rps).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
%
% play one strategy against another, for N moves.
%
play_two(S1, S2, N) ->
play_two(S1, S2, N, [], [], 0). %Added 0 variable to sum the score.
@7-fl
7-fl / rp3.erl
Last active March 12, 2017 21:40
Finished Implementing tests for apply_best_strat()
-module(rps).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
%
% play one strategy against another, for N moves.
%
play_two(StrategyL,StrategyR,N) ->
play_two(StrategyL,StrategyR,[],[],N).
@7-fl
7-fl / rp3.erl
Created March 11, 2017 22:10
rock/paper/scissors strategies
-module(rps).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
%
% play one strategy against another, for N moves.
%
play_two(StrategyL,StrategyR,N) ->
play_two(StrategyL,StrategyR,[],[],N).
@7-fl
7-fl / w3.erl
Last active March 10, 2017 07:06
iterate(), twice(), etc.
-module(w3).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
iterate_test() ->
Iter1 = iterate(1),
Iter2 = iterate(2),
Iter3 = iterate(3),
F1 = Iter1(fun(X) -> X+2 end),
@7-fl
7-fl / w3.erl
Last active March 9, 2017 12:54
zip_with, Rock/Paper/Scissors
-module(w3).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
%Win/Lose/Draw: The obvious choice would be to use an
%atom to represent those outcomes.
%But if you are playing the best of three plays, how
%would you decide who was the winner? For instance,
%one player's score might be {draw, won, won} and the
%other player's score would be {draw, lost, lost}.