Created
February 12, 2012 02:19
-
-
Save suryagaddipati/1805833 to your computer and use it in GitHub Desktop.
minimum from each each team
This file contains hidden or 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
| (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