blob: 41ce1eb75ebcad3a7f0947052184609aaabc81bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
from common import day
fh = open(f"input/{day()}")
X = 1
cycle = 0
r = 0
row = []
while True:
cycle += 1
pos = (cycle - 1) % 40
if pos == 0:
print("".join(row))
row = []
if pos in (X-1, X, X+1):
row.append("#")
else:
row.append(".")
try:
line = next(fh)
except StopIteration:
print(r)
break
line = line.rstrip()
match line.split():
case ["noop"]:
continue
case ["addx", val]:
val = int(val)
cycle += 1
pos = (cycle - 1) % 40
if pos == 0:
print("".join(row))
row = []
if pos in (X-1, X, X+1):
row.append("#")
else:
row.append(".")
X += val
|