Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lib/aoc_elixir/solutions/y25/day09.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule AocElixir.Solutions.Y25.Day09 do
alias AoC.Input

def parse(input, _part) do
Input.stream_file_lines(input, trim: true)
|> Stream.map(&(String.split(&1, ",") |> Enum.map(fn v -> v |> String.to_integer() end)))
end

def part_one(problem) do
# {[min_x, _], [max_x, _]} =
# problem
# |> Enum.min_max_by(fn v -> Enum.at(v, 0) end)
# {[_, min_y], [_, max_y]} =
# problem
# |> Enum.min_max_by(fn v -> Enum.at(v, 1) end)

problem
# |> Enum.filter(fn [px, py] ->
# px == min_x or py == min_y or px == max_x or py == max_y
# end)
|> unique_pairs(&area/1)
# |> IO.inspect(label: "pairs", charlists: false)
|> Enum.max_by(&elem(&1, 1))
|> elem(1)
end

defp area({[ax, ay], [bx, by]}) do
(abs(bx - ax) + 1) * (abs(ay - by) + 1)
end

def unique_pairs(list, func) do
list
|> Enum.with_index()
|> Enum.flat_map(fn {a, i} ->
list
|> Enum.drop(i + 1)
|> Enum.map(fn b ->
couple = {a, b}
{couple, func.(couple)}
end)
end)
end

# def part_two(problem) do
# problem
# end
end
56 changes: 56 additions & 0 deletions test/2025/day09_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
defmodule AocElixir.Solutions.Y25.Day09Test do
alias AoC.Input, warn: false
alias AocElixir.Solutions.Y25.Day09, as: Solution, warn: false
use ExUnit.Case, async: true

defp solve(input, part) do
problem =
input
|> Input.as_file()
|> Solution.parse(part)

apply(Solution, part, [problem])
end

test "part one example" do
input = ~S"""
7,1
11,1
11,7
9,7
9,5
2,5
2,3
7,3
"""

assert 50 == solve(input, :part_one)
end

@part_one_solution 4_755_429_952
@tag :solution
test "part one solution" do
assert {:ok, @part_one_solution} == AoC.run(2025, 9, :part_one)
end

# test "part two example" do
# input = ~S"""
# 7,1
# 11,1
# 11,7
# 9,7
# 9,5
# 2,5
# 2,3
# 7,3
# """
#
# assert 24 == solve(input, :part_two)
# end

# @part_two_solution CHANGE_ME
#
# test "part two solution" do
# assert {:ok, @part_two_solution} == AoC.run(2025, 9, :part_two)
# end
end