There's more than one way to do things | |
PerlMonks |
Re: x objects in y containers where all objects are usedby MidLifeXis (Monsignor) |
on Nov 06, 2009 at 17:06 UTC ( [id://805527]=note: print w/replies, xml ) | Need Help?? |
Assign the bucket to the number (instead of the number to the bucket), and you have a much easier to comprehend solution. As a sanity check, you will have Yx results. One approach, with 8 objects in 2 bins, would be to treat it as binary. A digit of '0' in position X would put item X into bucket 0. A digit of '1' in position X would put item X into bucket 1. If you iterate over all of the values for that binary number, you have just iterated over all of the solutions - in this case 256.
Extrapolate this to any value of X (8 above) and Y (2 above), and you have, I believe, your solution. Update: Added example data Update: You could also handle the case where all of the items do not need to be used by assigning a bin Y+1 as a hidden bin. --MidLifeXis
In Section
Seekers of Perl Wisdom
|
|