move getGrid inside, it's rainy
This commit is contained in:
parent
8552731beb
commit
6d77259384
35
day15.py
35
day15.py
@ -4,10 +4,22 @@ from tools.grid import Grid
|
||||
from typing import Any, List
|
||||
|
||||
|
||||
def getGrid(lines: List[str], multiply: bool = False) -> Grid:
|
||||
size = len(lines)
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
(40, "test_input15"),
|
||||
(386, "input15")
|
||||
],
|
||||
[
|
||||
(315, "test_input15"),
|
||||
(2806, "input15")
|
||||
]
|
||||
]
|
||||
|
||||
def getGrid(self, multiply: bool = False) -> Grid:
|
||||
size = len(self.getInput())
|
||||
g = Grid()
|
||||
for y, l in enumerate(lines):
|
||||
for y, l in enumerate(self.getInput()):
|
||||
for x, v in enumerate(map(int, l)):
|
||||
g.set(Coordinate(x, y), v)
|
||||
if not multiply:
|
||||
@ -23,26 +35,13 @@ def getGrid(lines: List[str], multiply: bool = False) -> Grid:
|
||||
|
||||
return g
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
(40, "test_input15"),
|
||||
(386, "input15")
|
||||
],
|
||||
[
|
||||
(315, "test_input15"),
|
||||
(2806, "input15")
|
||||
]
|
||||
]
|
||||
|
||||
def part1(self) -> Any:
|
||||
grid = getGrid(self.getInput())
|
||||
grid = self.getGrid()
|
||||
path = grid.getPath(Coordinate(0, 0), Coordinate(grid.maxX, grid.maxY), includeDiagonal=False, weighted=True)
|
||||
return sum(grid.get(c) for c in path[:-1])
|
||||
|
||||
def part2(self) -> Any:
|
||||
grid = getGrid(self.getInput(), True)
|
||||
grid = self.getGrid(True)
|
||||
path = grid.getPath(Coordinate(0, 0), Coordinate(grid.maxX, grid.maxY), includeDiagonal=False, weighted=True)
|
||||
return sum(grid.get(c) for c in path[:-1])
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user