Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2013 01:56
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 anonymous/ee3cfb4934510563253a to your computer and use it in GitHub Desktop.
Save anonymous/ee3cfb4934510563253a to your computer and use it in GitHub Desktop.
(def pairs [(8 2) (2 4) (3 9) (27 3) (9 3)])
(reduce (fn [currMap [a b]]
(let [match (first (filter (fn [group] (some #(or (= % a) (= % b) group))) currMap))]
(if match
(replace {match: (into match [a b])} currMap)
(into currMap [a b]))))
{}
pairs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment