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
import AOC | |
aoc 2023, 13 do | |
def p1(input) do | |
{xs, ys} = input |> grids() |> Enum.map(&calculate/1) |> Enum.unzip() | |
combine = fn items -> items |> List.flatten() |> Enum.map(fn n -> (1 + n)/2 end) |> Enum.sum() end | |
100*combine.(xs) + combine.(ys) | |
end | |
def p2(input) 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
import AOC | |
aoc 2023, 10 do | |
def p1(input) do | |
{_dots, {graph, start}} = input |> grid() |> parse() | |
search({[{start, []}], []}, graph |> Enum.map(&pipe/1) |> Map.new, %{}) | |
|> longest_path() | |
|> Enum.count() | |
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
import AOC | |
aoc 2023, 11 do | |
def calculate(input, multiplier) do | |
grid = grid(input) |> Map.new() | |
{rows, cols} = grid |> Enum.unzip() |> elem(0) |> Enum.unzip() | |
row_max = rows |> Enum.max() | |
col_max = cols |> Enum.max() | |
blank_rows = 0..row_max |> Enum.filter(fn row -> Enum.all?(0..col_max, fn col -> grid[{row, col}] == "." end) end) | |
blank_cols = 0..col_max |> Enum.filter(fn col -> Enum.all?(0..row_max, fn row -> grid[{row, col}] == "." end) 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
import AOC | |
aoc 2023, 9 do | |
def p1(input) do | |
parse(input) | |
|> Enum.map( | |
fn nums -> | |
nums | |
|> recurse | |
|> Enum.map(&Enum.reverse/1) |
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
import AOC | |
import Math, only: [lcm: 2] | |
aoc 2023, 8 do | |
def p1(input) do | |
{moves, map} = parse(input) | |
traverse("AAA", map, 0, moves, moves, &(&1 == "ZZZ")) | |
end | |
def extract(<<key::binary-3, " = (", left::binary-3, ", ", right::binary-3, ")">>), do: {key, {left, right}} |
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
import AOC | |
aoc 2023, 7 do | |
def p1(input), do: compute(input, &(&1), &value/1) | |
def p2(input), do: compute(input, &go_wild/1, &value2/1) | |
def compute(input, f, g) do | |
input | |
|> String.split("\n") |
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
import AOC | |
aoc 2023, 6 do | |
def p1(input) do | |
input | |
|> parse() | |
|> Enum.map(fn l -> Enum.map(l , &String.to_integer/1) end) | |
|> Enum.zip() | |
|> Enum.map(&possibilities/1) | |
|> Enum.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
import AOC | |
aoc 2023, 5 do | |
def p1(input) do | |
{seeds, maps} = process(input) | |
Enum.map(seeds, &maps_number(&1, maps)) |> Enum.min | |
end | |
def map_number([], n), do: n |
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
import AOC | |
aoc 2023, 4 do | |
def p1(input) do | |
input | |
|> winning_cards() | |
|> Enum.map(fn 0 -> 0; n -> 2 ** (n-1) end) | |
|> Enum.sum() | |
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
import AOC | |
aoc 2023, 3 do | |
def p1(input) do | |
{symbols, nums} = input |> String.split("", trim: true) |> parse({0,0}, {%{}, []}) | |
nums | |
|> Enum.filter(fn {indices, _} -> symbol_adjacent?(symbols, indices) end) | |
|> Enum.unzip | |
|> elem(1) | |
|> Enum.sum() |