~noelle/aoc-2021

62b549e35dfa35bc91f705258d92b29502fbc088 — Noelle Leigh 2 years ago aa2de69
09_1: black format
1 files changed, 20 insertions(+), 5 deletions(-)

M 09/puzzle_1.py
M 09/puzzle_1.py => 09/puzzle_1.py +20 -5
@@ 17,11 17,26 @@ if __name__ == "__main__":
    risk_level_sum = 0
    for row_index, row in enumerate(heightmap):
        for col_index, point in enumerate(row):
            left_neighbor = heightmap[row_index][col_index - 1] if col_index > 0 else None
            right_neighbor = heightmap[row_index][col_index + 1] if col_index < num_cols - 1 else None
            top_neighbor = heightmap[row_index - 1][col_index] if row_index > 0 else None
            bottom_neighbor = heightmap[row_index + 1][col_index] if row_index < num_rows - 1 else None
            neighbors = filter(lambda val: val is not None, [left_neighbor, right_neighbor, top_neighbor, bottom_neighbor])
            left_neighbor = (
                heightmap[row_index][col_index - 1] if col_index > 0 else None
            )
            right_neighbor = (
                heightmap[row_index][col_index + 1]
                if col_index < num_cols - 1
                else None
            )
            top_neighbor = (
                heightmap[row_index - 1][col_index] if row_index > 0 else None
            )
            bottom_neighbor = (
                heightmap[row_index + 1][col_index]
                if row_index < num_rows - 1
                else None
            )
            neighbors = filter(
                lambda val: val is not None,
                [left_neighbor, right_neighbor, top_neighbor, bottom_neighbor],
            )
            is_lowest = all(map(lambda val: val > point, neighbors))
            if is_lowest:
                risk_level = point + 1