Skip to content

Instantly share code, notes, and snippets.

@yayitswei
Created September 6, 2012 00:22
Show Gist options
  • Select an option

  • Save yayitswei/3648565 to your computer and use it in GitHub Desktop.

Select an option

Save yayitswei/3648565 to your computer and use it in GitHub Desktop.
(defn cost-comparator [x y]
(if (= x y)
0
(let [[f1 _ h1] x
[f2 _ h2] y]
(if (= f1 f2)
(if (< h1 h2) -1 1)
(if (< f1 f2) -1 1)))))
(def p (priority-map-by cost-comparator [3 6] [18 9 9 [4 5]], [2 7] [18 9 9 [3 8]], [1 8] [18 9 9 [2 9]], [3 5] [18 8 10 [4 4]], [5 3] [18 8 10 [4 4]], [2 6] [18 8 10 [3 7]], [1 7] [18 8 10 [2 8]], [4 3] [18 7 11 [3 3]], [3 4] [18 7 11 [3 3]], [2 5] [18 7 11 [3 6]], [2 4] [18 6 12 [3 3]], [4 2] [18 6 12 [3 3]], [3 2] [18 5 13 [2 2]], [2 3] [18 5 13 [2 2]], [1 3] [18 4 14 [2 2]], [3 1] [18 4 14 [2 2]], [2 1] [18 3 15 [1 1]], [1 2] [18 3 15 [1 1]], [1 0] [18 1 17 [0 0]]))
(peek p)
(-> p pop peek)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment