aoc
/
2022
1
0
Fork 0
2022/day10.py

34 lines
650 B
Python

import fileinput
reg_x = 1
cyc = 0
DURATIONS = {"noop": 1, "addx": 2}
part1 = 0
screen = [0] * 240
for line in fileinput.input():
mnem, *args = line.strip().split()
d = 0
for _ in range(DURATIONS[mnem]):
cyc += 1
if (cyc - 20) % 40 == 0:
part1 += cyc * reg_x
c = (cyc - 1) % 40 + 1
if reg_x == c or reg_x + 1 == c or reg_x + 2 == c:
screen[cyc - 1] = reg_x
match mnem:
case "noop":
pass
case "addx":
reg_x += int(args[0])
print(part1)
for i in range(0, 240, 40):
print("".join("#" if h else " " for h in screen[i : i + 40]))