31 lines
539 B
Python
31 lines
539 B
Python
import os
|
|
|
|
input = open(os.path.dirname(__file__) +
|
|
"/input.txt", "r").readlines()
|
|
|
|
cost = {
|
|
'noop': 1,
|
|
'addx': 2
|
|
}
|
|
|
|
cycle = 1
|
|
l = 0
|
|
finish = len(input)
|
|
X = 1
|
|
strs = []
|
|
|
|
for l in input:
|
|
cmd = l.split()
|
|
for i in range(cost[cmd[0]]):
|
|
#print(cycle, X, strs)
|
|
|
|
if ((cycle+20) % 40) == 0:
|
|
strenth = cycle*X
|
|
# print(">> " + str(cycle) + " " + str(strenth))
|
|
strs.append(strenth)
|
|
cycle += 1
|
|
if cmd[0] == 'addx':
|
|
X += int(cmd[1])
|
|
|
|
print(sum(strs))
|