aartist has asked for the
wisdom of the Perl Monks concerning the following question:

I am looking for combinations from multiple sets. For exmaple, I need 3 letters from 'a'..'z' and 2 digits from '0'..'9'. I can get single combination with Math::Combinatorics easily. Is there one for multiple set? ( Above sets are just examples, so a quick solution, for above case may not be useful).

Update:
My sets can overlap too. For exmaple I may have 4 sets like '0..7','1-6', '6-12',and '3..9'. I also need to eliminate duplicate items. In the case of overlapping sets, every resulting row should satisfy the initial condition. ie.. if I ask for 2 from '0..7' and 3 from '6..12', I should NOT have "6,7,6,7,8" or even "4,5,6,7,8" ( Here 0..7 has 4 entries rather than 2, as asked for.)

I hope I'm understanding the problem. Regardless, it was an interesting puzzle (and a great question).

I understand you to be saying that you want all possible merges of the combinations of set A with the combinations of set B. And I think that by mentioning the potential for overlap you're saying that any merge that would result in an overlap should be disqualified. I don't think it is sufficient to just generate all combinations of set A, and all combinations of set B, merge, and shuffle. That would not result in a result set of all possible non-overlapping merges.

My solution creates all possible combinations of set A (3 at a time), and then iterates over that list in an outer loop while merging all possible combinations of set B (taken 2 at a time) that don't result in an overlap of any elements. The implementation sacrifices speed efficiency in favor of memory efficiency; we never actually hold onto any full list of combinations of either set A or set B. We just use the iterators for each set. That means that the set B combination object will be created and destroyed on every iteration from set A.

...and if I totally missed the boat I'm anxious to see a correct interpretation and the resulting solution code! :)

Update: In the update to your original post, and further clarified in a message to me, I see that you may be needing to merge multiple sets of combinations (ie, more than just two). I don't see any solution that doesn't involve diving deeper and deeper into nested loops, driving your big-O complexity higher with each additional set of combinations.

Is this just one way of approaching a more general problem that you're trying to solve?

My sets can overlap too. For exmaple I may have 4 sets like '0..7','1-6', '6-12',and '3..9'. I also need to eliminate duplicate items. In the case of overlapping sets, every resulting row should satisfy the initial condition. ie.. if I ask for 2 from '0..7' and 3 from '6..12', I should NOT have "6,7,6,7,8" or even "4,5,6,7,8" ( Here 0..7 has 4 entries rather than 2, as asked for.)

With those conditions, nothing will satisfy if you'd have to pick at least one from '1..6'. Because any pick from that set will be a possible pick from the set '0..7', making that the count of picks from that set will be off.

If '0-7' has less number of picks compared to '1-6', then we will have no solution at all. But, it is possible that ('0-7','1-6') has (3,2) picks or even (2,2) picks respectively. In the first case there will be exactly 1 selection from 0 and 7 in any solution. In the 2nd case, 0 and 7 will not be selected in any solution.

Care to clarify that? Maybe add some examples? Cos like JavaFan, I don't get it.

As soon as you pick any two values from group 2 (1..6), you've also already picked two values from group 1 (0..7), so there is no way to comply with your "every resulting row should satisfy the initial condition" requirement.

You would either a) a pick two from both groups and therefore have 4 from the larger group; or b) pick nothing from the larger group, in which case you have nothing from the larger group.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.

"Science is about questioning the status quo. Questioning authority".

In the absence of evidence, opinion is indistinguishable from prejudice.

Then you can grep {...} the result to exclude some results. Of course, this is not very good with big sets or a lot of combinations (time and memory).

Update: I probably post the worst solution beacause you don't want to duplicate elements from set1 and set2. It's possible to "grep" the result to avoid duplicate but it is not beautiful/effective... Anyway, this usage of glob must be known, so I don't delete my contribution :)

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other