This file contains 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(advent16). | |
-compile([export_all]). | |
-define(PATTERN1, [{ children, 3 }, { cats, 7 }, { samoyeds, 2 }, { pomeranians, 3 }, | |
{ akitas, 0 }, { vizslas, 0 }, { goldfish, 5 }, { trees, 3 }, { cars, 2 }, | |
{ perfumes, 1 }]). | |
parseLine(Line) -> | |
{ ok, [ SueNum ], Rest } = io_lib:fread("Sue ~d: ", Line), |
This file contains 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(advent13). | |
-compile([export_all]). | |
parse_person(Str) -> | |
list_to_atom(string:strip(Str -- ".\n")). | |
parse_happiness("gain", Amount) -> list_to_integer(Amount); | |
parse_happiness("lose", Amount) -> -list_to_integer(Amount). |
This file contains 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(advent12). | |
%% depends on JSX <https://github.com/talentdeficit/jsx> for JSON processing | |
-export([main/0, main/1]). | |
red_is_bad([]) -> false; | |
red_is_bad([ { _, <<"red">> } | _ ]) -> true; | |
red_is_bad([_ | Rest ]) -> red_is_bad(Rest). |
This file contains 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
%#!/bin/env escript | |
%% | |
-mode(compile). | |
digit([]) -> []; | |
digit([C | Rest]) -> | |
digit(Rest, C, 1). | |
digit([], C, Count) -> | |
integer_to_list(Count) ++ [C]; |
This file contains 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(advent9). | |
-export([main/0, main/1]). | |
add_distance(From, To, Distance, Map) -> | |
[{{To, From}, Distance}, | |
{{From, To}, Distance} | Map ]. | |
find_distance(From, To, Map) -> | |
element(2, lists:keyfind({ From, To }, 1, Map)). |
This file contains 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(advent8). | |
-export([start/0]). | |
cleanUp(Input) -> | |
string:strip( | |
string:strip( | |
Input, both, $\n | |
) | |
). |
This file contains 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(advent6). | |
-export([start/0]). | |
init(Width, Height) -> | |
lists:duplicate(Height, lists:duplicate(Width, 0)). | |
count(Lights) -> | |
lists:sum(lists:flatten(Lights)). |
This file contains 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
% http://adventofcode.com/2016/day/11 | |
-module(advent11). | |
%-compile([export_all]). | |
-export([start/0, part1/0, part2/0, test/0]). | |
-record(state, { elevator = 1, floors }). | |
-define(TOP_FLOOR, 4). |
This file contains 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
// required to enable the feature | |
import scala.language.experimental.macros | |
import scala.reflect.macros.blackbox.Context | |
object MacroDefn { | |
def log(s: String): Unit = macro MacroImpl.log | |
} | |
object MacroImpl { | |
val verbose = util.Properties.propIsSet("test.logging") |
This file contains 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
function gitbase() { | |
local start=$PWD | |
cd $(while [[ ! -d ./.git ]]; do if [[ $PWD == "/" ]]; then echo $start; exit; fi; cd .. ; done; pwd); | |
} |