Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by moritz (Cardinal)
on Nov 06, 2009 at 14:08 UTC ( #805488=note: print w/replies, xml ) Need Help??


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

The answer has nothing to do with perl, only with math.

First you have to tell us if the containers have a maximal capacity; from your examples I'd guess so. If that's the case, the number of combinations is the factorial of the total capacity of all containers, divided by the product of the factorials of each capacity. So in your example

     6!
-----------
2! * 2! * 2!

This assumes that order insider containers doesn't matter, ie that 12 34 5 is the same as 21 34 5, but that the order of containers does matter. (If it doesn't, you need to divide by the factorial of number containers).

If that's not what you want, you have to provide a few more details.

Perl 6 - links to (nearly) everything that is Perl 6.
  • Comment on Re: x objects in y containers where all objects are used

Replies are listed 'Best First'.
Re^2: x objects in y containers where all objects are used
by blokhead (Monsignor) on Nov 06, 2009 at 14:35 UTC
    That formula (6! / 3(2!)) only applies if you have 6 items and put exactly two in each container. I don't think it expresses something about the maximal capacity, it's about a fixed capacity that you must put in each container.

    blokhead

      That formula (6! / 3(2!)) only applies if you have 6 items and put exactly two in each container.

      You're right. That's why I asked if my assumption was correct that the containers have limited capacity. If it were, distributing 5 elements on 3 containers with a capacity of 2 each is the same as distributing 6, where the sixth is the empty/missing element.

      I don't think it expresses something about the maximal capacity, it's about a fixed capacity that you must put in each container.

      If you have a maximal capacity, and add virtual filling items, the problem becomes very similar to a fixed capacity - except that you have to divide by the factorial of the number of filling items, which I forgot in my previous post.

      Perl 6 - links to (nearly) everything that is Perl 6.
Re^2: x objects in y containers where all objects are used
by Ectaris (Novice) on Nov 06, 2009 at 14:12 UTC

    My problem is that I don't need the number of combination's but the combination's themselves. Order does not matter and there containers do not have a maximum capacity.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2021-10-24 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?