summaryrefslogtreecommitdiff
path: root/3.jq
diff options
context:
space:
mode:
authorChristian Segundo2024-12-03 09:15:24 +0100
committerChristian Segundo2024-12-03 09:15:24 +0100
commitdb0a75e3c4f7f9f4cff7f74ec781276cdfee4dde (patch)
tree0267b045b58d5a03e5316f5e0ec4cef8fa9001fb /3.jq
parent32857c72e07b77fd3e8ab46407d883b630f32e86 (diff)
downloadadvent-of-code-2024-db0a75e3c4f7f9f4cff7f74ec781276cdfee4dde.tar.gz
add day 3
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"
+# ]