Created
January 1, 2014 09:50
-
-
Save tommyettinger/8206530 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This code needs to be removed | |
;; (def open (atom {})) | |
(defn dijkstra | |
([a] | |
(do (dijkstra a (find-walls a) (find-lowest a)))) | |
([a closed open-cells] | |
(let [open (transient open-cells)] | |
(while (not (empty? open)) | |
(let [newly-open (transient {})] | |
(doall (for [[i v] open] | |
(let [n (- i wide) | |
s (+ i wide) | |
w (- i 1 ) | |
e (+ i 1 ) | |
] | |
(if (or (closed n) (open n) (>= (inc v) (hiphip/aget a n))) nil (do (hiphip/aset a n (inc v)) (assoc! newly-open n (inc v)))) | |
(if (or (closed s) (open s) (>= (inc v) (hiphip/aget a s))) nil (do (hiphip/aset a s (inc v)) (assoc! newly-open s (inc v)))) | |
(if (or (closed w) (open w) (>= (inc v) (hiphip/aget a w))) nil (do (hiphip/aset a w (inc v)) (assoc! newly-open w (inc v)))) | |
(if (or (closed e) (open e) (>= (inc v) (hiphip/aget a e))) nil (do (hiphip/aset a e (inc v)) (assoc! newly-open e (inc v)))) | |
))) | |
(reset! open newly-open))) | |
a | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment