aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

commit d01e94705e0b6c140e8219c081fe5c2ca73e4888 (patch)
parent ef4880478bff5b35ace430b3d96038da2a63483d
Author: Alex Karle <alex@alexkarle.com>
Date:   Sat, 11 Dec 2021 16:04:44 -0500

day9: Remove "inf" border in favor of extra if's

I think this ultimately just reads cleaner than having the surrounding
inf boarder! No speedup, really.

Diffstat:
M09/a.py | 24+++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/09/a.py b/09/a.py @@ -1,34 +1,28 @@ #!/usr/bin/env python3 import sys -from math import inf - -grid = [[inf] * 102] +grid = [] for l in sys.stdin: - grid.append([inf] + [int(x) for x in l.strip()] + [inf]) + grid.append([int(x) for x in l.strip()]) -grid.append([inf] * 102) def lowest(r, c): pt = grid[r][c] - if grid[r-1][c] <= pt: + if r > 0 and grid[r - 1][c] <= pt: return False - if grid[r][c-1] <= pt: + if c > 0 and grid[r][c - 1] <= pt: return False - if grid[r][c+1] <= pt: + if c < 99 and grid[r][c + 1] <= pt: return False - if grid[r+1][c] <= pt: + if r < 99 and grid[r + 1][c] <= pt: return False return True + risk = 0 -for r in range(1, 101): - # print("") - for c in range(1, 101): +for r in range(100): + for c in range(100): if lowest(r, c): - # print(f"[{grid[r][c]}]", end="") risk += grid[r][c] + 1 - # else: - # print(f" {grid[r][c]} ", end="") print(risk)