Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: x objects in y containers where all objects are used

by MidLifeXis (Monsignor)
on Nov 06, 2009 at 17:06 UTC ( [id://805527]=note: print w/replies, xml ) Need Help??


in reply to x objects in y containers where all objects are used

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

Replies are listed 'Best First'.
Re^2: x objects in y containers where all objects are used
by Ectaris (Novice) on Nov 06, 2009 at 17:56 UTC

    I think I can make this work. Thanks for the great idea MidLifeXis.

Re^2: x objects in y containers where all objects are used
by jandrew (Chaplain) on Nov 08, 2009 at 04:55 UTC

      Ok, not quite what I understood. My understanding of the problem were that empty bins were allowed.

      In that case, my suggestion does nothing to make the solution easier, except that given X > Y, Yx << Xy (thanks Corion and moritz for the confirmation).

      Ok, given the numbers we are talking about, I guess that it could make it simpler.

      --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://805527]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-19 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found