aboutsummaryrefslogtreecommitdiff
path: root/2024/03/puzzle-2.sh
diff options
context:
space:
mode:
Diffstat (limited to '2024/03/puzzle-2.sh')
-rwxr-xr-x2024/03/puzzle-2.sh9
1 files changed, 9 insertions, 0 deletions
diff --git a/2024/03/puzzle-2.sh b/2024/03/puzzle-2.sh
new file mode 100755
index 0000000..cc8e677
--- /dev/null
+++ b/2024/03/puzzle-2.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+grep -Eo "(mul\\([0-9]+,[0-9]+\\)|do(n't)?\(\))" input \
+| awk 'BEGIN { FPAT = "[0-9]+"; go = 1 }
+ /do\(/ { go = 1 }
+ /don/ { go = 0 }
+ /mul/ && go { x += $1 * $2 }
+ END { print x }
+' \ No newline at end of file