From 9638fb3ee51f4cf0de8f44093845b25d53fb4738 Mon Sep 17 00:00:00 2001 From: setop Date: Tue, 3 Dec 2024 09:57:20 +0100 Subject: [PATCH] day 3, esay peazy, regexp + awk --- d03/run.awk | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 d03/run.awk diff --git a/d03/run.awk b/d03/run.awk new file mode 100644 index 0000000..03efa09 --- /dev/null +++ b/d03/run.awk @@ -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 +} \ No newline at end of file