aoc2022/d10/part1.py

24 lines
296 B
Python

import sys
X = 1
C = 0
S = []
I = {20, 60, 100, 140, 180, 220}
def inc():
global C
C += 1
if C in I:
S.append(C*X)
for l in sys.stdin.read().splitlines():
m, q = (l+" _").split(" ")[:2]
if m == "noop":
inc()
else: # add
inc()
inc()
X += int(q)
print(sum(S))