aboutsummaryrefslogtreecommitdiffstats
path: root/day10/partboth.clj
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
commit8d43e37df99f280377bed90284d6ac2428334804 (patch)
tree3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /day10/partboth.clj
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'day10/partboth.clj')
-rw-r--r--day10/partboth.clj34
1 files changed, 0 insertions, 34 deletions
diff --git a/day10/partboth.clj b/day10/partboth.clj
deleted file mode 100644
index 78080d9..0000000
--- a/day10/partboth.clj
+++ /dev/null
@@ -1,34 +0,0 @@
-(def to-closing {\{ \} \( \) \[ \] \< \>})
-(def to-score {\) 3 \] 57 \} 1197 \> 25137})
-(def to-score2 {\) 1 \] 2 \} 3 \> 4})
-
-(defn check-line [input]
- (loop [in input open '()]
- (if-let [c (first in)]
- (if (some->> (#{\} \) \] \>} c) (not= (first open)))
- c
- (recur
- (rest in)
- (if-let [op (to-closing c)]
- (conj open op)
- (rest open)
- )))
- open
- )))
-
-(->> (slurp "./in")
- (clojure.string/split-lines)
- (map (comp check-line vec))
- ; check-line returns first invalid character, or list of characters
- ; necessary to close the line. Work through these through `reduce`
- ; and build the answers for both parts:
- (reduce
- (fn [tots nxt]
- (if (seq? nxt)
- (update tots 1 #(conj % (reduce (fn [a b] (+ (* 5 a) (to-score2 b))) 0 nxt)))
- (update tots 0 #(+ % (to-score nxt)))))
- [0 '()])
- ; Get part 2 answer from the list of scores:
- (#(update % 1 (fn [ns] (nth ns (quot (count ns) 2)))))
- (println))
-