Skip to content

Commit 329b2ea

Browse files
committed
Add test
1 parent cdbf664 commit 329b2ea

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

lib/2023/day_10.ex

+6-12
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,26 @@ defmodule AdventOfCode.Y2023.Day10 do
55
Difficulty: xl
66
Tags: graph graph-traversal needs-improvement not-fast-enough
77
"""
8-
alias AdventOfCode.Helpers.{InputReader, Transformers}
98
alias AdventOfCode.Algorithms.Grid
10-
alias Geo.Polygon
11-
12-
import Topo, only: [contains?: 2]
9+
alias AdventOfCode.Helpers.{InputReader, Transformers}
1310

1411
def input, do: InputReader.read_from_file(2023, 10)
1512

1613
def run(input \\ input()) do
1714
input = parse(input)
18-
1915
task_1 = Task.async(fn -> run_1(input) end)
2016
task_2 = Task.async(fn -> run_2(input) end)
2117

2218
{Task.await(task_1, :infinity), Task.await(task_2, :infinity)}
2319
end
2420

25-
defp run_1({_, circuit}) do
26-
circuit |> Enum.count() |> div(2)
27-
end
21+
defp run_1({_, circuit}), do: circuit |> Enum.count() |> div(2)
2822

2923
defp run_2({graph, circuit}) do
3024
graph
3125
|> Graph.vertices()
3226
|> Stream.reject(&(&1 in circuit))
33-
|> Stream.map(&contains?(%Polygon{coordinates: [circuit]}, &1))
27+
|> Stream.map(&Topo.contains?(%Geo.Polygon{coordinates: [circuit]}, &1))
3428
|> Enum.count(&Function.identity/1)
3529
end
3630

@@ -40,10 +34,10 @@ defmodule AdventOfCode.Y2023.Day10 do
4034
|> Enum.map(&String.graphemes/1)
4135
|> Grid.grid2d()
4236
|> then(fn grid ->
43-
{start, _} = Enum.find(grid, fn {_, tile} -> tile == "S" end)
4437
graph = to_graph(grid)
45-
circuit = circuit_nodes(graph, start)
46-
{graph, circuit}
38+
{start, _} = Enum.find(grid, fn {_, tile} -> tile == "S" end)
39+
40+
{graph, circuit_nodes(graph, start)}
4741
end)
4842
end
4943

test/2023/day_10_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ defmodule AdventOfCode.Y2023.Day10Test do
77
alias AdventOfCode.Y2023.Day10, as: Solution
88

99
test "Year 2023, Day 10 run/1" do
10-
assert Solution.run() == {nil, nil}
10+
assert Solution.run() == {7107, 258}
1111
end
1212
end

0 commit comments

Comments
 (0)