diff --git a/d03/run.awk b/d03/run.awk index 03efa09..0da234c 100644 --- a/d03/run.awk +++ b/d03/run.awk @@ -1,26 +1,7 @@ # 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 -} \ No newline at end of file +# grep -oP 'mul\([0-9]+[,][0-9]+\)|do\(\)|don.t\(\)' input | tr '(,)' '\t\t\t' | awk -f this.awk +BEGIN {run=1} +$1=="mul" {P1+=$2*$3; P2+=run*$2*$3} +$1=="don't" {run=0} +$1=="do" {run=1} +END {print P1, P2}