tiny simplification
This commit is contained in:
parent
b9ca148096
commit
df718ad579
1 changed files with 2 additions and 4 deletions
|
@ -9,16 +9,14 @@ defmodule Day10 do
|
||||||
def find_trails(point, _grid, 9), do: [point]
|
def find_trails(point, _grid, 9), do: [point]
|
||||||
|
|
||||||
def find_trails({x, y}, grid, height) do
|
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)
|
|> Enum.flat_map(fn {point, _} -> find_trails(point, grid, height + 1) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_neighbours(x, y, height, grid) do
|
def find_neighbours(x, y, height, grid) do
|
||||||
next_height = height + 1
|
|
||||||
|
|
||||||
grid
|
grid
|
||||||
|> Map.take([{x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}])
|
|> 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
|
end
|
||||||
|
|
||||||
def part2({grid, zeros}) do
|
def part2({grid, zeros}) do
|
||||||
|
|
Loading…
Reference in a new issue