day 3, compact form

This commit is contained in:
setop 2025-01-04 19:24:56 +01:00
parent 124508cc31
commit dd493270fd
1 changed files with 6 additions and 25 deletions

View File

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