diff options
-rw-r--r-- | day12 | 24 | ||||
-rw-r--r-- | day12.clj | 38 |
2 files changed, 62 insertions, 0 deletions
diff --git a/day12 b/day12 new file mode 100644 index 0000000..fbb547b --- /dev/null +++ b/day12 @@ -0,0 +1,24 @@ +yb-start +de-vd +rj-yb +rj-VP +OC-de +MU-de +end-DN +vd-end +WK-vd +rj-de +DN-vd +start-VP +DN-yb +vd-MU +DN-rj +de-VP +yb-OC +start-rj +oa-MU +yb-de +oa-VP +jv-MU +yb-MU +end-OC diff --git a/day12.clj b/day12.clj new file mode 100644 index 0000000..15267fb --- /dev/null +++ b/day12.clj @@ -0,0 +1,38 @@ +(ns org.vuxu.aoc2021.day12 + (:require [clojure.string :as str])) + +(def data + (->> (slurp "day12") + (str/split-lines) + (map #(str/split % #"-")))) + +(def datamap + (update-vals + (group-by first + (concat + (map (comp vec reverse) data) + data)) + #(set (mapv second %)))) + +(defn dfs [path repeat?] + (if (= (last path) "end") + 1 + (apply + (for [n (datamap (last path))] + (cond (not (and (Character/isLowerCase (first n)) + (some #{n} path))) + (dfs (conj path n) repeat?) + + (and repeat? + (= (count (filter #{n} path)) 1) + (not= n "start")) + (dfs (conj path n) false) + + :else 0))))) + +(def part1 + (dfs ["start"] false)) +;; => 4411 + +(def part2 + (dfs2 ["start"] true)) +;; => 136767 |