day 10, awk solution for part 1

This commit is contained in:
setop 2022-12-10 19:56:16 +01:00
parent c089762042
commit 4a798e1095
1 changed files with 13 additions and 0 deletions

13
d10/part1.awk Normal file
View File

@ -0,0 +1,13 @@
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 }