Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from tommyettinger/gist:8206530
Last active January 1, 2016 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/8206664 to your computer and use it in GitHub Desktop.
Save amalloy/8206664 to your computer and use it in GitHub Desktop.
(defn dijkstra
([a]
(dijkstra a (find-walls a) (find-lowest a)))
([a closed open-cells]
(loop [open open-cells]
(when (seq open)
(recur (reduce (fn [newly-open [i v]]
(reduce (fn [acc dir]
(if (or (closed dir) (open dir)
(>= (inc v) (hiphip/aget a n)))
acc
(do (hiphip/aset a n (inc v))
(assoc acc n (inc v)))))
newly-open, [(- i wide)
(+ i wide)
(- i 1)
(+ i 1)]))
{}, open))))
a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment