-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd10.py
40 lines (36 loc) · 1.04 KB
/
d10.py
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
39
40
data = [x.strip('\n') for x in open("i10.txt").readlines()]
# data = [ x.strip('\n') for x in open("t10.txt").readlines() ]
def checkpix(c, x):
pos = (c-1) % 40
if pos in range(x-1, x+2):
return "#" + ("\n" if pos == 39 else "")
else:
return " " + ("\n" if pos == 39 else "")
cycle = 1
x = 1
res = 0
screen = ""
for l in data:
op, *n = l.split()
if op == 'noop':
if (cycle - 20) % 40 == 0 or (cycle - 20) % 40 == 0:
# print(cycle, x, cycle*x)
res += cycle*x
screen += checkpix(cycle, x)
cycle +=1
elif op == 'addx':
if (cycle - 20) % 40 == 0 or (cycle - 20) % 40 == 0:
# print(cycle, x, cycle*x)
res += cycle*x
screen += checkpix(cycle, x)
cycle +=1
if (cycle - 20) % 40 == 0 or (cycle - 20) % 40 == 0:
# print(cycle, x, cycle*x)
res += cycle*x
screen += checkpix(cycle, x)
cycle +=1
x += int(n[0])
else:
assert False
print(res)
print(screen)