From c5076758052e65f14811ff807dba98ef88ef5fc0 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 12 Dec 2021 12:12:41 -0500 Subject: day12: document part2, make part1 more concise --- day12/part1.clj | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'day12/part1.clj') diff --git a/day12/part1.clj b/day12/part1.clj index fe8ca7c..cdd4a43 100644 --- a/day12/part1.clj +++ b/day12/part1.clj @@ -7,21 +7,13 @@ (#(concat % (map reverse %))) )) -(def search-caves - (memoize (fn [id] - (filter #(= (first %) id) caves)))) - (defn get-caves-forward [klst] - (let [end (first klst)] - (if (str/starts-with? end "end") - [klst] - (map #(cons (second %) klst) - (filter - (fn [cv] - (or (< (int (first (second cv))) 96) - (not-any? #(= % (second cv)) klst))) - (search-caves end) - ))))) + (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 -- cgit v1.2.3