Skip to content

Instantly share code, notes, and snippets.

View AlejandroCatalina's full-sized avatar

Alejandro Catalina AlejandroCatalina

View GitHub Profile
@AlejandroCatalina
AlejandroCatalina / dijkstra.clj
Created November 23, 2015 11:29 — forked from valpackett/dijkstra.clj
Dijkstra's algorithm in Clojure
; http://www.algolist.com/Dijkstra's_algorithm
(defn dijkstra [g src]
(loop [dsts (assoc (zipmap (keys g) (repeat nil)) src 0)
curr src
unvi (apply hash-set (keys g))]
(if (empty? unvi)
dsts
(let [unvi (disj unvi curr)
nextn (first (sort-by #(% dsts) unvi))