day8
This commit is contained in:
parent
9219259cf8
commit
e0b0149449
58
day08.py
Normal file
58
day08.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from tools.coordinate import Coordinate
|
||||||
|
from tools.grid import Grid
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(6, "input8_test"),
|
||||||
|
(110, "input8"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
("ZJHRKCPLYJ", "input8"),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
def parse_input(self) -> Grid:
|
||||||
|
grid = Grid()
|
||||||
|
for line in self.getInput():
|
||||||
|
grid.maxX = 49
|
||||||
|
grid.maxY = 5
|
||||||
|
if line.startswith("rect"):
|
||||||
|
_, dim = line.split()
|
||||||
|
dx, dy = map(int, dim.split("x"))
|
||||||
|
for x in range(dx):
|
||||||
|
for y in range(dy):
|
||||||
|
grid.set(Coordinate(x, y))
|
||||||
|
elif line.startswith("rotate row"):
|
||||||
|
_, _, dy, _, shift = line.split()
|
||||||
|
shift = int(shift)
|
||||||
|
dy = int(dy[2:])
|
||||||
|
orig = grid.get_row(dy)
|
||||||
|
orig = orig[-shift:] + orig[:-shift]
|
||||||
|
for x, v in enumerate(orig):
|
||||||
|
grid.set(Coordinate(x, dy), v)
|
||||||
|
elif line.startswith("rotate column"):
|
||||||
|
_, _, dx, _, shift = line.split()
|
||||||
|
shift = int(shift)
|
||||||
|
dx = int(dx[2:])
|
||||||
|
orig = grid.get_column(int(dx))
|
||||||
|
orig = orig[-shift:] + orig[:-shift]
|
||||||
|
for y, v in enumerate(orig):
|
||||||
|
grid.set(Coordinate(dx, y), v)
|
||||||
|
|
||||||
|
return grid
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
return self.parse_input().getOnCount()
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
return self.parse_input().get_aoc_ocr_string()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
day = Day(2016, 8)
|
||||||
|
day.run(verbose=True)
|
||||||
153
inputs/input8
Normal file
153
inputs/input8
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
rect 1x1
|
||||||
|
rotate row y=0 by 2
|
||||||
|
rect 1x1
|
||||||
|
rotate row y=0 by 5
|
||||||
|
rect 1x1
|
||||||
|
rotate row y=0 by 3
|
||||||
|
rect 1x1
|
||||||
|
rotate row y=0 by 3
|
||||||
|
rect 2x1
|
||||||
|
rotate row y=0 by 5
|
||||||
|
rect 1x1
|
||||||
|
rotate row y=0 by 5
|
||||||
|
rect 4x1
|
||||||
|
rotate row y=0 by 2
|
||||||
|
rect 1x1
|
||||||
|
rotate row y=0 by 2
|
||||||
|
rect 1x1
|
||||||
|
rotate row y=0 by 5
|
||||||
|
rect 4x1
|
||||||
|
rotate row y=0 by 3
|
||||||
|
rect 2x1
|
||||||
|
rotate row y=0 by 5
|
||||||
|
rect 4x1
|
||||||
|
rotate row y=0 by 2
|
||||||
|
rect 1x2
|
||||||
|
rotate row y=1 by 6
|
||||||
|
rotate row y=0 by 2
|
||||||
|
rect 1x2
|
||||||
|
rotate column x=32 by 1
|
||||||
|
rotate column x=23 by 1
|
||||||
|
rotate column x=13 by 1
|
||||||
|
rotate row y=0 by 6
|
||||||
|
rotate column x=0 by 1
|
||||||
|
rect 5x1
|
||||||
|
rotate row y=0 by 2
|
||||||
|
rotate column x=30 by 1
|
||||||
|
rotate row y=1 by 20
|
||||||
|
rotate row y=0 by 18
|
||||||
|
rotate column x=13 by 1
|
||||||
|
rotate column x=10 by 1
|
||||||
|
rotate column x=7 by 1
|
||||||
|
rotate column x=2 by 1
|
||||||
|
rotate column x=0 by 1
|
||||||
|
rect 17x1
|
||||||
|
rotate column x=16 by 3
|
||||||
|
rotate row y=3 by 7
|
||||||
|
rotate row y=0 by 5
|
||||||
|
rotate column x=2 by 1
|
||||||
|
rotate column x=0 by 1
|
||||||
|
rect 4x1
|
||||||
|
rotate column x=28 by 1
|
||||||
|
rotate row y=1 by 24
|
||||||
|
rotate row y=0 by 21
|
||||||
|
rotate column x=19 by 1
|
||||||
|
rotate column x=17 by 1
|
||||||
|
rotate column x=16 by 1
|
||||||
|
rotate column x=14 by 1
|
||||||
|
rotate column x=12 by 2
|
||||||
|
rotate column x=11 by 1
|
||||||
|
rotate column x=9 by 1
|
||||||
|
rotate column x=8 by 1
|
||||||
|
rotate column x=7 by 1
|
||||||
|
rotate column x=6 by 1
|
||||||
|
rotate column x=4 by 1
|
||||||
|
rotate column x=2 by 1
|
||||||
|
rotate column x=0 by 1
|
||||||
|
rect 20x1
|
||||||
|
rotate column x=47 by 1
|
||||||
|
rotate column x=40 by 2
|
||||||
|
rotate column x=35 by 2
|
||||||
|
rotate column x=30 by 2
|
||||||
|
rotate column x=10 by 3
|
||||||
|
rotate column x=5 by 3
|
||||||
|
rotate row y=4 by 20
|
||||||
|
rotate row y=3 by 10
|
||||||
|
rotate row y=2 by 20
|
||||||
|
rotate row y=1 by 16
|
||||||
|
rotate row y=0 by 9
|
||||||
|
rotate column x=7 by 2
|
||||||
|
rotate column x=5 by 2
|
||||||
|
rotate column x=3 by 2
|
||||||
|
rotate column x=0 by 2
|
||||||
|
rect 9x2
|
||||||
|
rotate column x=22 by 2
|
||||||
|
rotate row y=3 by 40
|
||||||
|
rotate row y=1 by 20
|
||||||
|
rotate row y=0 by 20
|
||||||
|
rotate column x=18 by 1
|
||||||
|
rotate column x=17 by 2
|
||||||
|
rotate column x=16 by 1
|
||||||
|
rotate column x=15 by 2
|
||||||
|
rotate column x=13 by 1
|
||||||
|
rotate column x=12 by 1
|
||||||
|
rotate column x=11 by 1
|
||||||
|
rotate column x=10 by 1
|
||||||
|
rotate column x=8 by 3
|
||||||
|
rotate column x=7 by 1
|
||||||
|
rotate column x=6 by 1
|
||||||
|
rotate column x=5 by 1
|
||||||
|
rotate column x=3 by 1
|
||||||
|
rotate column x=2 by 1
|
||||||
|
rotate column x=1 by 1
|
||||||
|
rotate column x=0 by 1
|
||||||
|
rect 19x1
|
||||||
|
rotate column x=44 by 2
|
||||||
|
rotate column x=40 by 3
|
||||||
|
rotate column x=29 by 1
|
||||||
|
rotate column x=27 by 2
|
||||||
|
rotate column x=25 by 5
|
||||||
|
rotate column x=24 by 2
|
||||||
|
rotate column x=22 by 2
|
||||||
|
rotate column x=20 by 5
|
||||||
|
rotate column x=14 by 3
|
||||||
|
rotate column x=12 by 2
|
||||||
|
rotate column x=10 by 4
|
||||||
|
rotate column x=9 by 3
|
||||||
|
rotate column x=7 by 3
|
||||||
|
rotate column x=3 by 5
|
||||||
|
rotate column x=2 by 2
|
||||||
|
rotate row y=5 by 10
|
||||||
|
rotate row y=4 by 8
|
||||||
|
rotate row y=3 by 8
|
||||||
|
rotate row y=2 by 48
|
||||||
|
rotate row y=1 by 47
|
||||||
|
rotate row y=0 by 40
|
||||||
|
rotate column x=47 by 5
|
||||||
|
rotate column x=46 by 5
|
||||||
|
rotate column x=45 by 4
|
||||||
|
rotate column x=43 by 2
|
||||||
|
rotate column x=42 by 3
|
||||||
|
rotate column x=41 by 2
|
||||||
|
rotate column x=38 by 5
|
||||||
|
rotate column x=37 by 5
|
||||||
|
rotate column x=36 by 5
|
||||||
|
rotate column x=33 by 1
|
||||||
|
rotate column x=28 by 1
|
||||||
|
rotate column x=27 by 5
|
||||||
|
rotate column x=26 by 5
|
||||||
|
rotate column x=25 by 1
|
||||||
|
rotate column x=23 by 5
|
||||||
|
rotate column x=22 by 1
|
||||||
|
rotate column x=21 by 2
|
||||||
|
rotate column x=18 by 1
|
||||||
|
rotate column x=17 by 3
|
||||||
|
rotate column x=12 by 2
|
||||||
|
rotate column x=11 by 2
|
||||||
|
rotate column x=7 by 5
|
||||||
|
rotate column x=6 by 5
|
||||||
|
rotate column x=5 by 4
|
||||||
|
rotate column x=3 by 5
|
||||||
|
rotate column x=2 by 5
|
||||||
|
rotate column x=1 by 3
|
||||||
|
rotate column x=0 by 4
|
||||||
4
inputs/input8_test
Normal file
4
inputs/input8_test
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
rect 3x2
|
||||||
|
rotate column x=1 by 1
|
||||||
|
rotate row y=0 by 4
|
||||||
|
rotate column x=1 by 1
|
||||||
Loading…
Reference in New Issue
Block a user