Skip to content

Instantly share code, notes, and snippets.

View rugyoga's full-sized avatar

Guy Argo rugyoga

  • San Francisco
View GitHub Profile
@rugyoga
rugyoga / AOC2023Day10.ex
Created December 13, 2023 03:56
Advent of Code 2023 Day 10
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
@rugyoga
rugyoga / AOC2023Day11.ex
Created December 11, 2023 05:53
Advent of Code 2023 Day 11
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)
@rugyoga
rugyoga / AOC2023Day09.ex
Created December 9, 2023 06:35
Advent of Code 2023 Day 9
import AOC
aoc 2023, 9 do
def p1(input) do
parse(input)
|> Enum.map(
fn nums ->
nums
|> recurse
|> Enum.map(&Enum.reverse/1)
@rugyoga
rugyoga / AOC2023Day08.ex
Last active December 9, 2023 00:08
Advent of Code 2023 day 8
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}}
@rugyoga
rugyoga / AOC2023Day07.ex
Last active December 9, 2023 00:02
Advent of Code 2023 Day 7
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")
@rugyoga
rugyoga / AOC2023Day06.ex
Last active December 6, 2023 21:37
Advent of code 2023 Day 6
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()
@rugyoga
rugyoga / AOC2023Day05.ex
Last active December 9, 2023 00:18
Advent of Code 2023 day 5
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
@rugyoga
rugyoga / AOC2023Day04.ex
Last active December 4, 2023 18:12
Advent of Code 2023 day 4
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
@rugyoga
rugyoga / AOC2023Day03.ex
Created December 4, 2023 04:04
Advent fo code 2023 Day 3
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()
@rugyoga
rugyoga / AOC2023Day02.ex
Last active December 2, 2023 23:28
Advent of Code 2023 Day 2
import AOC
import String, only: [split: 2, to_integer: 1]
import Enum, only: [map: 2, max: 1, product: 1, reduce: 3, sum: 1, zip_with: 2]
aoc 2023, 2 do
def parse_game(line) do
["Game " <> id, hands] = split(line, ": ")
{to_integer(id), hands |> split("; ") |> map(&parse_hand/1)}
end