From 426b3ef609bb1d81dbf2df18f7a75856f35d9b42 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Tue, 30 Nov 2021 12:41:40 +0100 Subject: [PATCH] day11 --- day11.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ inputs/input11 | 1 + 2 files changed, 56 insertions(+) create mode 100644 day11.py create mode 100644 inputs/input11 diff --git a/day11.py b/day11.py new file mode 100644 index 0000000..338c8b9 --- /dev/null +++ b/day11.py @@ -0,0 +1,55 @@ +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" diff --git a/inputs/input11 b/inputs/input11 new file mode 100644 index 0000000..b1a2f81 --- /dev/null +++ b/inputs/input11 @@ -0,0 +1 @@ +3,8,1005,8,332,1106,0,11,0,0,0,104,1,104,0,3,8,102,-1,8,10,101,1,10,10,4,10,108,1,8,10,4,10,101,0,8,28,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,51,1,1103,5,10,1,1104,9,10,2,1003,0,10,1,5,16,10,3,8,102,-1,8,10,101,1,10,10,4,10,108,0,8,10,4,10,1001,8,0,88,1006,0,2,1006,0,62,2,8,2,10,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,1,10,4,10,102,1,8,121,1006,0,91,1006,0,22,1006,0,23,1006,0,1,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,155,1006,0,97,1,1004,2,10,2,1003,6,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,1002,8,1,187,1,104,15,10,2,107,9,10,1006,0,37,1006,0,39,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,0,8,10,4,10,102,1,8,223,2,2,17,10,1,1102,5,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,1001,8,0,253,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,1,10,4,10,1002,8,1,276,1006,0,84,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,0,10,4,10,1001,8,0,301,2,1009,9,10,1006,0,10,2,102,15,10,101,1,9,9,1007,9,997,10,1005,10,15,99,109,654,104,0,104,1,21102,1,936995738516,1,21101,0,349,0,1105,1,453,21102,1,825595015976,1,21102,1,360,0,1105,1,453,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21102,46375541763,1,1,21101,0,407,0,1105,1,453,21102,1,179339005019,1,21101,0,418,0,1106,0,453,3,10,104,0,104,0,3,10,104,0,104,0,21102,825012036372,1,1,21102,441,1,0,1105,1,453,21101,988648461076,0,1,21101,452,0,0,1105,1,453,99,109,2,22102,1,-1,1,21102,40,1,2,21102,484,1,3,21101,0,474,0,1106,0,517,109,-2,2105,1,0,0,1,0,0,1,109,2,3,10,204,-1,1001,479,480,495,4,0,1001,479,1,479,108,4,479,10,1006,10,511,1102,1,0,479,109,-2,2105,1,0,0,109,4,2102,1,-1,516,1207,-3,0,10,1006,10,534,21101,0,0,-3,21202,-3,1,1,22101,0,-2,2,21102,1,1,3,21102,553,1,0,1106,0,558,109,-4,2106,0,0,109,5,1207,-3,1,10,1006,10,581,2207,-4,-2,10,1006,10,581,22102,1,-4,-4,1105,1,649,21202,-4,1,1,21201,-3,-1,2,21202,-2,2,3,21101,0,600,0,1105,1,558,21201,1,0,-4,21101,0,1,-1,2207,-4,-2,10,1006,10,619,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,641,22102,1,-1,1,21102,1,641,0,106,0,516,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2105,1,0