36 lines
551 B
Python
36 lines
551 B
Python
|
|
cycle = 0
|
|
X = 1
|
|
T = 0
|
|
def step():
|
|
global T
|
|
global cycle
|
|
cycle += 1
|
|
if cycle in (20, 60, 100, 140, 180, 220):
|
|
ss = cycle * X
|
|
T += ss
|
|
|
|
px = (cycle-1) % 40
|
|
if abs(X - px) <= 1:
|
|
# sprite is visible
|
|
img.append('#')
|
|
else:
|
|
img.append(' ')
|
|
|
|
|
|
img = []
|
|
|
|
for line in open("input"):
|
|
ins = line.strip()
|
|
if ins == "noop":
|
|
step()
|
|
else:
|
|
step()
|
|
step()
|
|
X += int(line.split()[1])
|
|
|
|
print (T)
|
|
|
|
for i in range(0, len(img), 40):
|
|
print(''.join(img[i:i+40]))
|