from tools.aoc import AOCDay from tools.aoc_ocr import convert_array_6 from typing import Any class Day(AOCDay): inputs = [ [ (13140, "input10_test"), (14620, "input10_dennis"), (13180, "input10"), ], [ ("BJFRHRFU", "input10_dennis"), ("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]) return convert_array_6(crt) if __name__ == '__main__': day = Day(2022, 10) day.run(verbose=True)