from intcode import IntCode from tools.aoc import AOCDay from tools.coordinate import Coordinate from tools.grid import Grid from typing import Any MOVEMENTS = [Coordinate(0, -1), Coordinate(1, 0), Coordinate(0, 1), Coordinate(-1, 0)] class Day(AOCDay): inputs = [ [ (2373, "input11") ], [ ("PCKRLPUK", "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] return hull.get_aoc_ocr_string(x_shift=1) if __name__ == '__main__': day = Day(2019, 11) day.run(verbose=True)