diff --git a/day09.py b/day09.py index 66517d6..d9a66e4 100644 --- a/day09.py +++ b/day09.py @@ -15,17 +15,9 @@ def getCaveMapFromInput(puzzle_input: List[str]) -> Grid: def getLowPoints(caveMap: Grid) -> List[Coordinate]: lowPoints = [] - for x in range(caveMap.minX, caveMap.maxX + 1): - for y in range(caveMap.minY, caveMap.maxY + 1): - thisPoint = Coordinate(x, y) - lowest = True - - for t in thisPoint.getNeighbours(includeDiagonal=False): - if caveMap.get(t) <= caveMap.get(Coordinate(x, y)): - lowest = False - - if lowest: - lowPoints.append(thisPoint) + for point in caveMap.getActiveCells(): + if not sum((caveMap.get(t) <= caveMap.get(point)) for t in point.getNeighbours(includeDiagonal=False)): + lowPoints.append(point) return lowPoints @@ -35,7 +27,7 @@ def getBasin(caveMap: Grid, start: Coordinate, visited: set) -> set: if n in visited: continue - if caveMap.get(n) != 9 and caveMap.get(n) != 99: + if caveMap.get(n) < 9: visited.add(n) visited = set.union(visited, getBasin(caveMap, n, visited))