diff options
Diffstat (limited to 'day10.clj')
-rw-r--r-- | day10.clj | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/day10.clj b/day10.clj new file mode 100644 index 0000000..b838b0d --- /dev/null +++ b/day10.clj @@ -0,0 +1,31 @@ +(ns org.vuxu.aoc2021.day10 + (:require [clojure.string :as str])) + +(defn fix [f x] + (loop [x x] + (let [fx (f x)] + (if (= x fx) x (recur fx))))) + +(let [[incomplete corrupted] + (->> (slurp "day10") + (str/split-lines) + (map (partial fix #(str/replace % #"\(\)|\[\]|\{\}|<>" ""))) + ((juxt filter remove) (partial re-find #"[)}>\]]")))] + (def incomplete incomplete) + (def corrupted corrupted)) + +(def part1 + (->> incomplete + (map (partial some #{\) \] \} \>})) + (map {\) 3 \] 57 \} 1197 \> 25137}) + (apply +))) +;; => 216297 + +(def part2 + (->> corrupted + (map reverse) + (map (partial map {\( 1 \[ 2 \{ 3 \< 4})) + (map (partial reduce #(+ (* %1 5) %2) 0)) + sort + (#(nth % (bit-shift-right (count corrupted) 1))))) +;; => 2165057169 |