From f04827c346263205b27c10ea2d6193fbd81b96f6 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 17 Dec 2022 23:01:29 +0000 Subject: [PATCH] Solve AOC day 13 pt 2 --- projects/aoc/src/year2022/Day13.kiss | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/projects/aoc/src/year2022/Day13.kiss b/projects/aoc/src/year2022/Day13.kiss index 9018ab2c..2677c02d 100644 --- a/projects/aoc/src/year2022/Day13.kiss +++ b/projects/aoc/src/year2022/Day13.kiss @@ -35,8 +35,28 @@ (let [[left right] (for line pair (Json.parse line))] (case (isInOrder left right) (Good (+ 1 idx)) - (Inconclusive (print (first pair)) (print (second pair)) (print "INCONCLUSIVE")) - (otherwise (continue))))))) + (Bad (continue)) + (never otherwise)))))) (assertEquals 13 (apply + (indicesInOrder "src/year2022/inputs/day13example.txt"))) -(assertEquals 6420 (apply + (indicesInOrder (input 13)))) \ No newline at end of file +(assertEquals 6420 (apply + (indicesInOrder (input 13)))) + +(function sortedPackets [file] + (let [packets (Util.readLines file)] + (packets.push "[[2]]") + (packets.push "[[6]]") + (packets.sort ->[left right] + (case (isInOrder (Json.parse left) (Json.parse right)) + (Good -1) + (Bad 1) + (never otherwise))) + packets)) + +(let [sp (sortedPackets "src/year2022/inputs/day13example.txt")] + (assertEquals 9 (sp.indexOf "[[2]]")) + (assertEquals 13 (sp.indexOf "[[6]]"))) + +(let [sp (sortedPackets (input 13))] + (let [a (sp.indexOf "[[2]]") + b (sp.indexOf "[[6]]")] + (assertEquals 22000 #{(a+1) * (b+1);}}#))) \ No newline at end of file