day 3, esay peazy, regexp + awk

This commit is contained in:
setop 2024-12-03 09:57:20 +01:00
parent 2f31d7d84f
commit 9638fb3ee5
1 changed files with 26 additions and 0 deletions

26
d03/run.awk Normal file
View File

@ -0,0 +1,26 @@
# run with
# grep -oP 'mul\([0-9]+[,][0-9]+\)|do\(\)|don.?t\(\)' input | tr '(,)' '\t\t\t' | awk -f this.awk
BEGIN {
run = 1
}
$1 == "mul" {
m = $2 * $3
P1 += m
if (run) {
P2 += m
}
}
$1 == "don't" {
run = 0
}
$1 == "do" {
run = 1
}
END {
print P1, P2
}