You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
628 B

lines = open('input.txt', "r").read().splitlines()
cycle = 0
x = 1
signals = [20, 60, 100, 140, 180, 220]
strengths = []
for line in lines:
cmd = line.split(" ")
if len(signals) == 0:
signals.append(9999999)
elif cycle == signals[0]:
strengths.append(x *cycle)
signals.pop(0)
elif cycle + 1 == signals[0]:
strengths.append(x * (cycle+1))
signals.pop(0)
elif cycle + 2 == signals[0]:
strengths.append(x * (cycle+2))
signals.pop(0)
if cmd[0] == "noop":
cycle += 1
else:
cycle += 2
x += int(cmd[1])
print(sum(strengths))