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:

C:\test>junk39 -M=3 -N=2 -I=1e4 90 { 112233 => 117, 112323 => 119, 112332 => 120, 113223 => 112, 113232 => 104, 113322 => 115, 121233 => 121, 121323 => 118, 121332 => 97, 122133 => 114, 122313 => 97, 122331 => 112, 123123 => 122, 123132 => 118, 123213 => 118, 123231 => 121, 123312 => 95, 123321 => 105, 131223 => 101, 131232 => 116, 131322 => 112, 132123 => 110, 132132 => 120, 132213 => 114, 132231 => 134, 132312 => 101, 132321 => 103, 133122 => 122, 133212 => 105, 133221 => 113, 211233 => 113, 211323 => 114, 211332 => 86, 212133 => 135, 212313 => 107, 212331 => 113, 213123 => 117, 213132 => 115, 213213 => 131, 213231 => 113, 213312 => 120, 213321 => 114, 221133 => 120, 221313 => 119, 221331 => 103, 223113 => 107, 223131 => 100, 223311 => 109, 231123 => 115, 231132 => 119, 231213 => 119, 231231 => 106, 231312 => 122, 231321 => 107, 232113 => 117, 232131 => 93, 232311 => 108, 233112 => 103, 233121 => 110, 233211 => 92, 311223 => 107, 311232 => 132, 311322 => 94, 312123 => 102, 312132 => 105, 312213 => 95, 312231 => 121, 312312 => 98, 312321 => 111, 313122 => 94, 313212 => 122, 313221 => 114, 321123 => 110, 321132 => 105, 321213 => 127, 321231 => 113, 321312 => 117, 321321 => 107, 322113 => 122, 322131 => 91, 322311 => 108, 323112 => 126, 323121 => 97, 323211 => 98, 331122 => 111, 331212 => 120, 331221 => 91, 332112 => 116, 332121 => 123, 332211 => 100, }

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!!