summaryrefslogtreecommitdiff
path: root/3.jq
diff options
context:
space:
mode:
Diffstat (limited to '3.jq')
-rw-r--r--3.jq32
1 files changed, 32 insertions, 0 deletions
diff --git a/3.jq b/3.jq
new file mode 100644
index 0000000..7317c71
--- /dev/null
+++ b/3.jq
@@ -0,0 +1,32 @@
+# jq --raw-input --slurp -f 3.jq <3-input.txt
+
+def p1(i):
+ [
+ i |
+ scan("(mul\\(\\d+,\\d+\\))") |
+ .[] |
+ match("(\\d+),(\\d+)") |
+ (.captures[0].string|tonumber) * (.captures[1].string|tonumber)
+ ] | add;
+
+def p2(i):
+ [
+ i |
+ gsub("\n"; "") |
+ splits("do\\(\\)") |
+ gsub("don't\\(\\).*"; "") |
+ scan("(mul\\(\\d+,\\d+\\))") |
+ .[] |
+ match("(\\d+),(\\d+)") |
+ (.captures[0].string|tonumber) * (.captures[1].string|tonumber)
+ ] | add;
+
+[
+ "puzzle 1: \(. as $input | p1($input))",
+ "puzzle 2: \(. as $input | p2($input))"
+] | .[]
+
+# [
+# "puzzle 1: 164730528",
+# "puzzle 2: 70478672"
+# ]