Skip to content

Instantly share code, notes, and snippets.

@suryagaddipati
Created February 12, 2012 02:19
Show Gist options
  • Select an option

  • Save suryagaddipati/1805833 to your computer and use it in GitHub Desktop.

Select an option

Save suryagaddipati/1805833 to your computer and use it in GitHub Desktop.
minimum from each each team
(defn incr-count [m x y]
(assoc m x (inc(get m x 0)) y (inc(get m y 0))))
(defn count-reducer [m team]
(let [[x y] team]
(incr-count m x y )))
(defn choose-winner [cmap , x , y] (if (> (get cmap x) (get cmap y)) x y ))
(defn unique-reducer [cmap]
(fn [m pair]
(let [[x y] pair]
(assoc m (choose-winner cmap x y) 1 ))))
(defn unique [x]
(let [cmap (reduce count-reducer {} x)]
(keys (reduce (unique-reducer cmap) {} x))))
(unique [[2 8]
[3 4]
[4 3]
[3 6]
[6 2]
[6 4]
[6 8]
[2 4]
[2 6]
[8 9]
[1 7]
[2 6]
[2 8]
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment