diff options
author | Christian Segundo | 2024-12-03 09:15:24 +0100 |
---|---|---|
committer | Christian Segundo | 2024-12-03 09:15:24 +0100 |
commit | db0a75e3c4f7f9f4cff7f74ec781276cdfee4dde (patch) | |
tree | 0267b045b58d5a03e5316f5e0ec4cef8fa9001fb /3.jq | |
parent | 32857c72e07b77fd3e8ab46407d883b630f32e86 (diff) | |
download | advent-of-code-2024-db0a75e3c4f7f9f4cff7f74ec781276cdfee4dde.tar.gz |
add day 3
Diffstat (limited to '3.jq')
-rw-r--r-- | 3.jq | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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" +# ] |