Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created July 27, 2011 03:08
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 amalloy/1108576 to your computer and use it in GitHub Desktop.
Save amalloy/1108576 to your computer and use it in GitHub Desktop.
(defn group-indices [coll]
(loop [[head & tail] coll
new-ids {}
next-id 0
ret []]
(let [found-id (get new-ids head)
[new-ids next-id] (if found-id
[new-ids next-id]
[(assoc new-ids head next-id) (inc next-id)])]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment