From db0a75e3c4f7f9f4cff7f74ec781276cdfee4dde Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Tue, 3 Dec 2024 09:15:24 +0100 Subject: add day 3 --- 3.jq | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 3.jq (limited to '3.jq') 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" +# ] -- cgit v1.2.3