day 10, awk solution for part 1
This commit is contained in:
11
d10/part1.awk
Normal file
11
d10/part1.awk
Normal file
@@ -0,0 +1,11 @@
|
||||
BEGIN { x=1 }
|
||||
function inc() {
|
||||
c+=1
|
||||
S += index("20,60,100,140,180,220,", c ",")>0 ? x*c : 0
|
||||
}
|
||||
{ inc() }
|
||||
$1 == "addx" {
|
||||
inc()
|
||||
x+=$2
|
||||
}
|
||||
END { print S }
|
Reference in New Issue
Block a user