aboutsummaryrefslogtreecommitdiffstats
path: root/day15/part1.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 /day15/part1.clj
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'day15/part1.clj')
-rw-r--r--day15/part1.clj30
1 files changed, 0 insertions, 30 deletions
diff --git a/day15/part1.clj b/day15/part1.clj
deleted file mode 100644
index 7838e34..0000000
--- a/day15/part1.clj
+++ /dev/null
@@ -1,30 +0,0 @@
-(def input (->> (slurp "./in")
- (clojure.string/split-lines)
- (mapv (partial mapv (comp read-string str)))
- (#(for [y (range 0 (count %)) x (range 0 (count (first %)))]
- {[y x] (get-in % [y x])}))
- (into {})))
-
-(def dim (apply max (map first (keys input))))
-
-(defn find-neighbors [u]
- (filter #(contains? input %) [(update u 0 inc)
- (update u 0 dec)
- (update u 1 inc)
- (update u 1 dec)]))
-
-(loop [dist (zipmap (keys input) (repeat ##Inf))
- Q {[0 0] 0}]
- (if (empty? Q)
- (println (dist [dim dim]))
- (let [[u distu] (first Q)
- NN (reduce
- #(let [dv (+ distu (input %2))]
- (cond-> %1
- (> ((first %1) %2) dv)
- (-> (update 0 assoc %2 dv)
- (update 1 assoc %2 dv))))
- [dist {}]
- (find-neighbors u))]
- (recur (first NN) (sort-by val < (into (rest Q) (second NN)))))))
-