Skip to content

Instantly share code, notes, and snippets.

@joeytrapp
joeytrapp / aoc_3.erl
Last active December 9, 2024 06:58
Advent of Code 2024 Day 3 Part 1 and Part 2
-module(aoc).
-export([main/1]).
main([Path]) ->
{ok, Data1} = file:read_file(Path, [read, binary]),
io:format("Without modes: ~p~n", [read_char(Data1, skip, 0)]),
{ok, Data2} = file:read_file(Path, [read, binary]),
io:format("With modes: ~p~n", [read_char(Data2, do, 0)]),
erlang:halt(0).
@joeytrapp
joeytrapp / aoc_4.erl
Created December 5, 2024 04:04
Advent of Code Day 4 Part 1 and Part 2
-module(aoc).
-export([main/1]).
main([Path]) ->
{ok, Content} = file:read_file(Path),
Data = fill(Content),
YSize = array:size(Data),
XSize = array:size(array:get(0, Data)),
persistent_term:put(?MODULE, Data),
@joeytrapp
joeytrapp / aoc_5.erl
Created December 6, 2024 06:53
Advent of Code Day 5 Part 1 and Part 2
-module(aoc).
-export([main/1]).
main([Path]) ->
{ok, Content} = file:read_file(Path),
{Rules, Edits} = parse(Content),
{Correct, Incorrect} = classify_edits(Edits, Rules),
Corrected = corrections(Incorrect, Rules),
io:format("Originally Correct: ~p~n", [sum_of_middles(Correct)]),
@joeytrapp
joeytrapp / aoc_6.erl
Last active December 7, 2024 19:08
Advent of Code Day 6 Part 1 and Part 2
-module(aoc).
-export([main/1]).
main([Path]) ->
{ok, Content} = file:read_file(Path),
{Grid, [Guard]} = parse(Content),
Complete = rounds(Grid, Guard),
Tests = sets:del_element(element(2, Guard), Complete),
io:format("Visited: ~p~n", [sets:size(Complete)]),
@joeytrapp
joeytrapp / aoc_7.erl
Last active December 8, 2024 05:59
Advent of Code Day 7 Part 1 and Part 2 (code only solves Part 2)
-module(aoc).
-export([main/1]).
main([Path]) ->
{ok, Content} = file:read_file(Path),
Data = parse(Content),
io:format("Result: ~p~n", [lists:sum(lists:map(fun test/1, Data))]),
erlang:halt(0).
@joeytrapp
joeytrapp / aoc_8.erl
Last active December 9, 2024 06:51
Advent of Code Day 8 Part 1 and Part 2
-module(aoc).
-export([main/1]).
main([Path]) ->
{ok, Content} = file:read_file(Path),
{Nodes, Max} = nodes(Content, 0, 0, {0,0}, #{}),
Anti = maps:fold(fun(_, L, S) ->
antinodes(L, L, Max, S)
end, sets:new(), Nodes),