Skip to content

Instantly share code, notes, and snippets.

-module(ex1_shapes).
-export([perimeter/1,test_perimeter/0,area/1,test_area/0,enclose/1,test_enclose/0,run_tests/0]).
%% Perimeter function and tests
perimeter({circle, R}) ->
{ok, math:pi() * 2 * R};
perimeter({rectangle, {A, B}}) ->
{ok, 2 * A + 2 * B};
perimeter({square, A}) ->
{ok, 4 * A};
-module(ex1_bits).
-export([bits_direct/1,test_bits_direct/0,bits_tail/2,test_bits_tail/0,run_tests/0]).
bits_direct(0) ->
0;
bits_direct(N) ->
N rem 2 + bits_direct(N div 2).
bits_tail(0, B) ->
B;
-module(index).
-export([get_file_contents/1
,show_file_contents/1
,main/1
% for tests
,get_words/4
,get_numbered_words/1
,sort_word_pair/2
,test_sort_word_pair/0
-module(hofex).
-export([add/1,times/1,compose/2,id/1,iterate/1
, compose_all/1
, test_compose_all/0
, twice/1
, test_twice/0
, test_iterate/0
]).
add(X) ->
-module(rps_game).
-export([play/1,echo/1,play_two/3,play_two/4,rock/1,no_repeat/1,const/1,enum/1,cycle/1,rand/1,val/1,tournament/2
, least_freq/1
, most_freq/1
, rand_strategies/1
, best_strategy/1
, t_const/1
, t_cycle/1
, t_echo/0
%% 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(frequency2).
-export([start/0,allocate/0,deallocate/1,stop/0]).
@fswalker
fswalker / billing.erl
Last active April 11, 2017 20:52
Small program simulating simple store with mocked DB and some basic operations. Test are located at the end of the file.
-module(billing).
-export([ get_data/0
, get_barcodes/0
, get_bill/3
, print_bill/1
, test_print_bill/0
, test_print_bill2/0
, test_print_bill3/0
]).
@fswalker
fswalker / frequency.erl
Created April 24, 2017 20:55
Solution of assignment no. 2 in Week 2 of Concurrent Programming in Erlang MOOC
%% 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
% Using the observer, set up a system of frequency server and at least two clients, and kill the frequency server when the clients are in possession of a frequency – you can make the clients “sleep” at any point using the timer:sleep/1 function – observe that the clients are killed too.
% How would you modify the clients so that they are not affected by the server terminating? How could you then shut down the entire system if you needed to?
%% 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(gf).
-behaviour(gen_server).
@fswalker
fswalker / Alphabet.elm
Created September 16, 2017 16:15
Generate list of capital letters from 'A' to 'Z'
module Alphabet exposing (..)
import Char
capitalLetters : List Char
capitalLetters =
List.range (Char.toCode 'A') (Char.toCode 'Z')
|> List.map Char.fromCode