title: Can I find all multisets of given size more efficiently?
body: <p>Given a set of possible values and a number of "digits," I want to find every unique, unordered grouping of values. For example, say you have an alphabet of A, B, C. All the combinations of 3 digits would be:</p>
  
  <pre><code>AAA
  AAB
  ABB
  BBB
  BBC
  BCC
  CCC
  CCA
  CAA
  ABC
  </code></pre>
  
  <p>The specific problem I'm trying to solve is a bit simpler. I'm doing a BlackJack game as an exercise in F# (<a href="https://stackoverflow.com/questions/2253462/is-there-an-existing-pattern-to-generate-a-list-of-the-applications-of-a-function/">I've posted about this before</a>). The way I'm calculating hand values is with a list of lists of cards' possible values. All cards except the Ace have a single item in the list, but the Aces can be either 1 or 11. The implementation I came up with in that post generates a lot of redundancy. For example, 3 aces would create a list like <code>[3; 13; 13; 13; 23; 23; 23; 33]</code>. Right now I'm taking the final list and running it through <code>Distinct()</code>, but it feels like a bit of a hack.</p>
  
  <p>Tying this all together, the Aces' potential values (1, 11) constitutes the alphabet, and the number of aces in the hand determines the number of digits. In this case, I would want the algorithm to come up with the following pattern:</p>
  
  <pre><code>1, 1 
  1, 11
  11,11
  </code></pre>
  
  <p>Something tells me <a href="http://en.wikipedia.org/wiki/Dynamic_programming" rel="nofollow noreferrer">Dynamic Programming</a> may come into play here, but my lack of appropriate terminology is leaving me a bit stuck. Any help would be appreciated.</p>
  
  <h3>Edit</h3>
  
  <p>For what it's worth, I'm aware that there are much simpler solutions to the specific problem, but being an exercise in functional programming, generality is one of my goals.</p>