diff --git a/2024/day10.exs b/2024/day10.exs index 94e65a8..ac38f26 100644 --- a/2024/day10.exs +++ b/2024/day10.exs @@ -9,16 +9,14 @@ defmodule Day10 do def find_trails(point, _grid, 9), do: [point] def find_trails({x, y}, grid, height) do - find_neighbours(x, y, height, grid) + find_neighbours(x, y, height + 1, grid) |> Enum.flat_map(fn {point, _} -> find_trails(point, grid, height + 1) end) end def find_neighbours(x, y, height, grid) do - next_height = height + 1 - grid |> Map.take([{x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}]) - |> Enum.filter(&match?({_, ^next_height}, &1)) + |> Enum.filter(&match?({_, ^height}, &1)) end def part2({grid, zeros}) do