29 lines
583 B
Lua
29 lines
583 B
Lua
io.input("test2")
|
|
io.input("input")
|
|
|
|
local cycle = 1
|
|
local x = 1
|
|
local strengths = 0
|
|
for line in io.lines() do
|
|
local ins, num = string.match(line, "^(%a+) (-?%d+)$")
|
|
-- print(cycle, (cycle-19)%40, x)
|
|
local period = (cycle-20)%40
|
|
if period == 0 then
|
|
print(cycle, x)
|
|
strengths = strengths + cycle*x
|
|
elseif num and period == 39 then
|
|
strengths = strengths + (cycle+1)*x
|
|
print(cycle, x)
|
|
end
|
|
|
|
if num then -- addx
|
|
cycle = cycle + 2
|
|
x = x + tonumber(num)
|
|
else
|
|
cycle = cycle + 1
|
|
end
|
|
end
|
|
|
|
print("x", x, "cycle", cycle)
|
|
print("part 1", strengths)
|