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

Update: Late breaking semi-possibility

  1. For M=3, N=2; (M*N)! := 720 and 720/90 = 8 (MN?)
  2. For M=3, N=3; (M*N)! := 362880 and 362880/1680 = 216. (But 33 is only 27) However, 63 :=216 ??? )
  3. For M=3, N=4; (M*N)! := 479001600 and 479001600/34650 = 13824. It's a whole number, so probably right, but how is it derived! ???

    Update2: 13824 is 29 * 33; but how you get that from 3 & 4 or 12 & 3 or 12 & 4???

  4. For M=3. N=4; (M*n)! := 1307674368000 and 1307674368000/7556756 = 1728000; And that is 29 * 33 * 53!?

If you have N identical sets of M different things, how many different orderings can they be arranged in? (Ie. What's the formula?)

Eg. if you have 2 sets of 3: my %stats; ++$stats{ join'', shuffle( ( 1..3 ) x 2 ) } for 1 .. 1e6

For the above example, with M=3 and varying N, I gets the following numbers:

  1. N=2 => 90
  2. N=3 => 1680 (*18.6667)
  3. N=4 => 34650 (*20.625)
  4. N=5 => 756756 (*21.84)

And for M=4:

  1. N=2 => 2520
  2. N=3 => 369600 (*146.6667)
  3. N=4 => 42283219 (at least; and probably much higher)

And for M=5:

  1. N=2 => 113400
  2. N=3 => ??? (Too big for memory)

Oh. And for the "What have you tried" crowd: I've been thinking about it for days; I've stared at the various algorithms in Algorithm::Combinatorics trying to work out which is applicable; and a few unsuccessful google searches looking for a relevant problem description.

As you can see, the numbers compound very quickly; and I need to calculate for considerably higher numbers; but I cannot wrap my brain around it.

For the very simplest (first) case above I get these results:

If you count the number of 1s,2s,& 3s in the 6 columns they are all equal at 30; hence 90 possible comb/permutations. But if there was a free choice of digit for all positions; it would be 36==729 combinations.

And if you could treat each group separately as permutations, and combined them it would be 3! * 3! = 36.

At this point, I've run out of ideas, so ... this post.


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". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re: Combinatorics formula
by tybalt89 (Monsignor) on Oct 19, 2016 at 00:03 UTC
    $N=2;$M=3;factorial($N*$M)/factorial($N)**$M 90 $N=3;$M=5;factorial($N*$M)/factorial($N)**$M 168168000

    from my REPL

      Thankyou both!!

Re: Combinatorics formula
by pryrt (Abbot) on Oct 19, 2016 at 00:06 UTC

    I think it's (M*N)! / (N!)**M.

    There are (M*N)! ways to organize all the items; there are N! identical arrangements of item #1-of-M, so you divide by that; there are N! if the ith item of M, so you also have to divide by that... in the end, there are N groups of M! you need to divide by.

      Thankyou both!!