cartman94501 (cartman94501) wrote in perl,

Pulling unique combos from a multiset

What's the fastest way to iterate over an ordered list and pull out only unique combos? The particular application here is unique seven-letter racks drawn from a fresh bag of Scrabble tiles. In other words, calling a blank @ for ease of ASCII ordering, my first draw is @@AAAAA, and there are 2C2 * 9C5 ways to draw it. The next one is @@AAAAB, and there are 2C2 * 9C4 * 2C1 ways to draw it. Then @@AAAAC, etc. all the way to @@AAAAZ, then down to three As like @@AAABB, @@AAABC, @@AAACC, etc., ending with VWWXYYZ (two ways). Given a hash such as:

(@ => 2,
A => 9,
B => 2,
C => 2,
D => 4,
E => 12,
X => 1,
Y => 2,
Z => 1)

what's the quickest way extract the unique combos? Once I have a unique combo, I can very quickly calculate the number of ways to pull it, but iterating over the list of unique combos is the hard part, at least for me.

Ideas? Thanks in advance.

  • Post a new comment


    default userpic