61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
from intcode import IntCode
|
|
from tools.aoc import AOCDay
|
|
from tools.coordinate import Coordinate
|
|
from tools.grid import Grid, GridTransformation
|
|
from typing import Any
|
|
|
|
MOVEMENTS = [Coordinate(0, -1), Coordinate(1, 0), Coordinate(0, 1), Coordinate(-1, 0)]
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(2373, "input11")
|
|
],
|
|
[
|
|
("see image above", "input11")
|
|
]
|
|
]
|
|
|
|
def part1(self) -> Any:
|
|
comp = IntCode(self.getInputAsArraySplit(",", int))
|
|
comp.start()
|
|
|
|
hull = Grid()
|
|
face = 0
|
|
pos = Coordinate(0, 0)
|
|
painted = set()
|
|
|
|
while not comp.isHalted():
|
|
comp.addInput(int(hull.isSet(pos)))
|
|
hull.set(pos, comp.getOutput())
|
|
painted.add(pos)
|
|
face += 1 if comp.getOutput() else -1
|
|
pos = pos + MOVEMENTS[face % 4]
|
|
|
|
return len(painted)
|
|
|
|
def part2(self) -> Any:
|
|
comp = IntCode(self.getInputAsArraySplit(",", int))
|
|
comp.start()
|
|
|
|
hull = Grid()
|
|
face = 0
|
|
pos = Coordinate(0, 0)
|
|
hull.set(pos, True)
|
|
|
|
while not comp.isHalted():
|
|
comp.addInput(hull.isSet(pos))
|
|
hull.set(pos, comp.getOutput())
|
|
face += 1 if comp.getOutput() else -1
|
|
pos = pos + MOVEMENTS[face % 4]
|
|
|
|
hull.print(true_char='#', false_char=' ')
|
|
|
|
return "see image above"
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2019, 11)
|
|
day.run(verbose=True)
|