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.

00000000 => (87654321), () 00000001 => (8765432), (1) 00000010 => (8765431), (2) 00000011 => (876543), (21) 00000100 => (8765421), (3) ... 11111111 => (), (87654321)

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 reply to Re: x objects in y containers where all objects are used by MidLifeXis
in thread x objects in y containers where all objects are used by Ectaris

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.