Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. *generate combinations*
  2.  
  3. If I have 4 flowers to choose from (`#{:rose :lily :daisy :tulip}`), I can generate 4 different combinations of 3 flowers.
  4.  
  5. ```clojure
  6. (#{:rose :lily :daisy}, #{:rose :lily :tulip}, #{:rose :daisy :tulip}, #{:lily
  7. :daisy :tulip})
  8. ```
  9.  
  10. Write a function combinations that takes a collection of values and a number of items to choose and generates all combinations of that size.
  11.  
  12. Example:
  13.  
  14. ```clojure
  15. (defn combinations [coll n]
  16. ...)
  17.  
  18. (combinations #{:rose :lily :daisy :tulip} 3)
  19. ; => (#{:rose :lily :daisy}, #{:rose :lily :tulip}, #{:rose :daisy :tulip},
  20. #{:lily :daisy :tulip})
  21. ```
  22.  
  23. Bonus points for clarity, interest, and efficiency.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement