aoc2022/day10.py
2022-12-10 08:13:53 +01:00

68 lines
1.6 KiB
Python

from tools.aoc import AOCDay
from typing import Any
class Day(AOCDay):
inputs = [
[
(13140, "input10_test"),
(14620, "input10_dennis"),
(13180, "input10"),
],
[
("EZFCHJAB", "input10"),
]
]
def part1(self) -> Any:
score = 0
scored = set()
cycle = 0
register = 1
for line in self.getInput():
cycle += 1
if line.startswith('addx'):
cycle += 1
if (cycle - 20) % 40 == 0 or (cycle - 21) % 40 == 0 or (cycle - 22) % 40 == 0:
cy_mul = cycle - ((cycle - 20) % 40)
if cy_mul not in scored:
score += cy_mul * register
scored.add(cy_mul)
if line.startswith('addx'):
register += int(line.split(" ")[-1])
return score
def part2(self) -> Any:
crt = [[' '] * 40 for _ in range(6)]
cycle = 0
register = 1
for line in self.getInput():
y = cycle // 40
x = cycle % 40
if x - 1 <= register <= x + 1:
crt[y][x] = '#'
cycle += 1
y = cycle // 40
x = cycle % 40
if x - 1 <= register <= x + 1:
crt[y][x] = '#'
if line.startswith('addx'):
cycle += 1
register += int(line.split(" ")[-1])
for l in crt:
print("".join(l))
return ""
if __name__ == '__main__':
day = Day(2022, 10)
day.run(verbose=True)