aoc2022/d10/part1.awk

13 lines
158 B
Awk

BEGIN { x=1 }
function inc() {
c+=1
if (index("20,60,100,140,180,220,", c ",")>0) {
S += x*c
}
}
{ inc() }
$1 == "addx" {
inc()
x+=$2
}
END { print S }