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
//---------------------------------------------------------------------------- | |
// recursive golfed reduce | |
//---------------------------------------------------------------------------- | |
let r = (f, a, [h, ...t]) => !t.length ? f(a, h) : r(f, f(a, h), t) | |
function reduce(fn, acc, [x, ...xs]) { | |
return !xs.length | |
? fn(acc, x) | |
: reduce(fn, fn(acc, x), 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
# Compares two maps and generates a list of actions that can be applied to the | |
# first map to transform it into the second. | |
# | |
# diff = difference(m1, m2) | |
# apply(m1, diff) === m2 | |
defmodule MapDiffGolf do | |
def difference(%{} = m1, %{} = m2), do: | |
for {k, v} <- m2, |
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
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Log Reader - polls log file and sends new lines to channel | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
defmodule LogReader do | |
use GenServer | |
@log_file "priv/some_log.log" | |
@poll_interval 5 * 1000 # 5 seconds | |
def run_test() do |
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(super). | |
-export([start/0, init/0]). | |
%% Starts the supervisor in it's own process | |
start() -> | |
spawn(super, init, []). | |
%% Initializes the supervisor with it's children | |
init() -> | |
process_flag(trap_exit, true), |
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(returning_funs). | |
-compile(export_all). | |
-type unary() :: fun((Term) -> Term). | |
% composes a function onto another F(G(X)) | |
-spec compose(unary(), unary()) -> unary(). | |
compose(F, G) -> | |
fun (X) -> F(G(X)) end. |
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(assignment2). | |
-export([print_indexes/1]). | |
-export([get_indexes/1, get_top_n_words/2, get_alpha_indexes/1]). | |
-define(SPLIT_TOKENS, " .,'\"()[]{}!?-\\"). | |
% Gets all of the indexes. | |
get_indexes(Filename) -> | |
maps:to_list(get_indexes_ranges(Filename)). |
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(more_functions_over_lists). | |
-export([join/2, concat/1]). | |
-export([reverse/1]). | |
-export([member/2]). | |
-export([merge_sort/1, quick_sort/1, insertion_sort/1]). | |
-export([permutations/1]). | |
join([], Ys) -> Ys; | |
join([X | Xs], 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
def encode(key, pt): | |
"""Encodes the plaintext using key.""" | |
return "".join([encode_single(x, y) for x, y in get_pairs(key, pt)]) | |
def decode(key, ct): | |
"""Decodes the ciphertext using key.""" | |
return "".join([decode_single(x, y) for x, y in get_pairs(key, ct)]) | |
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(functions_over_lists). | |
-export([product/1]). | |
-export([maximum/1]). | |
-export([product_fold/1]). | |
product(X) -> product(X, 1). | |
product([], Product) -> Product; | |
product([X | Xs], Product) -> product(Xs, X * Product). |
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). | |
-export([area/1]). | |
-export([perimeter/1]). | |
-export([enclose/1]). | |
-export([tail_bits/1]). | |
-export([direct_bits/1]). | |
% Define shape types | |
% coordinate pair |
NewerOlder