64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
from tools.coordinate import Coordinate
|
|
from tools.grid import Grid
|
|
|
|
from intcode import IntCode
|
|
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(3192, "input17"),
|
|
],
|
|
[
|
|
(None, "input17"),
|
|
]
|
|
]
|
|
|
|
def getGrid(self) -> Grid:
|
|
comp = IntCode(self.getInputAsArraySplit(",", int))
|
|
comp.start()
|
|
grid = Grid()
|
|
x, y = 0, 0
|
|
while comp.isRunning() or comp.hasOutput():
|
|
c = comp.getOutput()
|
|
if c == 10:
|
|
x, y = 0, y + 1
|
|
else:
|
|
grid.set(Coordinate(x, y), chr(c))
|
|
x = x + 1
|
|
|
|
return grid
|
|
|
|
def part1(self) -> Any:
|
|
grid = self.getGrid()
|
|
sum = 0
|
|
for x in grid.rangeX():
|
|
for y in grid.rangeY():
|
|
if grid.get(Coordinate(x, y)) != '#':
|
|
continue
|
|
|
|
crossing = True
|
|
for c in Coordinate(x, y).getNeighbours(includeDiagonal=False):
|
|
if grid.get(c) != '#':
|
|
crossing = False
|
|
break
|
|
|
|
if crossing:
|
|
sum = sum + (x * y)
|
|
|
|
return sum
|
|
|
|
def part2(self) -> Any:
|
|
# L,4,R,8,L,6,L,10,L,6,R,8,R,10,L,6,L,6,L,4,R,8,L,6,L,10,L,6,R,8,R,10,L,6,L,6,L,4,L,4,L,10,L,4,L,4,L,10,L,6,R,8,R,10,L,6,L,6,L,4,R,8,L,6,L,10,L,6,R,8,R,10,L,6,L,6,L,4,L,4,L,10
|
|
main_routine = "A,A,B,B,C,A,B"
|
|
# L,4,R,8,L,6,L,10,L,6 # ,R,8,R,10,L,6,L,6
|
|
# L,4,L,4,L,10
|
|
# L,6,R,8,R,10,L,6,L,6
|
|
return ""
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2019, 17)
|
|
day.run(verbose=True)
|