from aoc import AOCDay from coordinate import Coordinate from grid import Grid, GridTransformation from intcode import IntCode from typing import Any MOVEMENTS = [Coordinate(0, -1), Coordinate(1, 0), Coordinate(0, 1), Coordinate(-1, 0)] class Day(AOCDay): test_solutions_p1 = [] test_solutions_p2 = [] def part1(self) -> Any: comp = IntCode(self.getInputAsArraySplit(",", int)) comp.start() hull = Grid() face = 0 pos = Coordinate(0, 0) painted = {} while not comp.isHalted(): comp.addInput(hull.isSet(pos)) hull.set(pos, comp.getOutput()) painted[pos] = True 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.transform(GridTransformation.ROTATE_RIGHT) hull.transform(GridTransformation.FLIP_HORIZONTALLY) for x in range(hull.minX, hull.maxX + 1): for y in range(hull.minY, hull.maxY + 1): print("#" if hull.isSet(Coordinate(x, y)) else " ", end="") print() return "see image above"