tiny simplification

This commit is contained in:
Adam Millerchip 2024-12-10 23:34:24 +09:00
parent b9ca148096
commit df718ad579

View file

@ -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