From df718ad579765f08634fc46b7033b4904b462360 Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Tue, 10 Dec 2024 23:34:24 +0900 Subject: [PATCH] tiny simplification --- 2024/day10.exs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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