Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *generate combinations*
- If I have 4 flowers to choose from (`#{:rose :lily :daisy :tulip}`), I can generate 4 different combinations of 3 flowers.
- ```clojure
- (#{:rose :lily :daisy}, #{:rose :lily :tulip}, #{:rose :daisy :tulip}, #{:lily
- :daisy :tulip})
- ```
- Write a function combinations that takes a collection of values and a number of items to choose and generates all combinations of that size.
- Example:
- ```clojure
- (defn combinations [coll n]
- ...)
- (combinations #{:rose :lily :daisy :tulip} 3)
- ; => (#{:rose :lily :daisy}, #{:rose :lily :tulip}, #{:rose :daisy :tulip},
- #{:lily :daisy :tulip})
- ```
- Bonus points for clarity, interest, and efficiency.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement