Skip to content

Instantly share code, notes, and snippets.

@Mu-adventofcode
Created April 30, 2022 20:12
Show Gist options
  • Save Mu-adventofcode/eec5fe5dc9a64e7da8502b1107528f49 to your computer and use it in GitHub Desktop.
Save Mu-adventofcode/eec5fe5dc9a64e7da8502b1107528f49 to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 09 part 1
with open("input.txt") as f:
data = [[int(d) for d in row.strip()] for row in f]
(max_x, max_y) = (len(data[0]) - 1, len(data) - 1)
inf = float("Inf")
risk_levels = [
height + 1
for y, row in enumerate(data)
for x, height in enumerate(row)
if height
< min(
data[y][x - 1] if x > 0 else inf,
data[y][x + 1] if x < max_x else inf,
data[y - 1][x] if y > 0 else inf,
data[y + 1][x] if y < max_y else inf,
)
]
print(sum(risk_levels))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment