daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top