This commit is contained in:
bluepython508
2023-12-18 09:19:27 +00:00
parent 3fc1300387
commit a9519aebbf
8 changed files with 90 additions and 8 deletions

View File

@@ -13,8 +13,6 @@ defmodule Aoc2023.Day10 do
?S => []
}
defp add_coords({y, x}, {y_, x_}), do: {y + y_, x + x_}
defp path(s_conns, conns) do
loop = fn recur, checked, checking ->
checked_ = MapSet.union(checked, checking)
@@ -53,7 +51,7 @@ defmodule Aoc2023.Day10 do
|> Enum.map(fn {c, x} ->
{
{y, x},
Map.get(@connections, c) |> Enum.map(pipe(add_coords({y, x})))
Map.get(@connections, c) |> Enum.map(pipe(add_vec({y, x})))
}
end)
end)
@@ -71,7 +69,7 @@ defmodule Aoc2023.Day10 do
end
def part2({{sy, sx}, s_conns, grid, path}) do
s_dirs = s_conns |> Enum.map(pipe(add_coords({-sy, -sx}))) |> Enum.sort()
s_dirs = s_conns |> Enum.map(pipe(add_vec({-sy, -sx}))) |> Enum.sort()
s_char = @connections |> Enum.find(fn {_, conns} -> Enum.sort(conns) == s_dirs end) |> elem(0)
grid_ = grid |> list_map_at(sy, pipe(map_nth(0, pipe(List.replace_at(sx, s_char)))))