Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created March 7, 2017 21:14
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 deque-blog/9c5dab1fedc8dd408d57953700cb930e to your computer and use it in GitHub Desktop.
Save deque-blog/9c5dab1fedc8dd408d57953700cb930e to your computer and use it in GitHub Desktop.
(defn zip
"Create a sequence of tuples, each element being drawn from one collection"
[& colls]
(apply map vector colls))
(defn pick-n-of-each
"Pick n `elements` for each of the `groups` starting from the beginning"
[n elements groups]
(zip elements (mapcat #(repeat n %) groups)))
(defn randomly-pick-n-of-each
"Pick n `elements` for each of the `groups` randomly"
[n elements groups]
(pick-n-of-each n (shuffle elements) groups))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment