From 8d43e37df99f280377bed90284d6ac2428334804 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 30 Nov 2022 19:55:31 -0500 Subject: move 2021 days to folder; update README --- year2021/day12/part1.clj | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 year2021/day12/part1.clj (limited to 'year2021/day12/part1.clj') diff --git a/year2021/day12/part1.clj b/year2021/day12/part1.clj new file mode 100644 index 0000000..cdd4a43 --- /dev/null +++ b/year2021/day12/part1.clj @@ -0,0 +1,27 @@ +(require '[clojure.string :as str]) + +(def caves (->> (slurp "./in") + (str/split-lines) + (map #(str/split % #"-")) + (map (partial map str)) + (#(concat % (map reverse %))) + )) + +(defn get-caves-forward [klst] + (map #(cons (second %) klst) + (filter + #(or (< (int (first (second %))) 96) + (not-any? (partial = (second %)) klst)) + (filter #(= (first %) (first klst)) caves) + ))) + +(loop [lst (get-caves-forward ["start"]) ms '()] + (let [nxt (->> lst + (map get-caves-forward) + (apply concat)) + mtchs (concat ms (filter #(= (first %) "end") nxt)) + nxtlst (filter #(not= (first %) "end") nxt)] + (if (empty? nxtlst) + (println (count mtchs)) + (recur nxtlst mtchs)))) + -- cgit v1.2.3