I am able to do a permutation counr for the set {a, a, b} which gives me 3 groups. I am happy with that result. However, if the set is {a, a, b, c, c, d}, Mathematica gives me all the possible groups, but it is difficult to count the number of groups. Can Mathematica find the total number of groups? If so, which function to do I use?

  • 1
    $\begingroup$ I must be missing the question. But isn't the length of the list the same as number of groups? Length@Permutations[{a, a, b, c, c, d}] gives 180. Or you looking for some other number? $\endgroup$
    – Nasser
    Dec 26, 2013 at 6:22
  • 1
    $\begingroup$ @Nasser I agree that is unclear how the word 'group' is to be interpreted. The first answer counted permutations. I merely presented another approach for that objective. OP will presumably clarify. $\endgroup$
    – ubpdqn
    Dec 26, 2013 at 13:12

3 Answers 3


You can count the permutations using Multinomial:





{3, 180, 6}


Length@Permutations[...] certainly suffices but for larger multisets I would just define a function that does not find all the permutations and instead uses the explicit formula if the number of permutations is all that is of interest.

PermutationCount[list_List] := 
 With[{len = Length@list, dups = Length /@ Gather[list]}, 
  len!/Times @@ Factorial /@ dups]
PermutationCount[{a, a, b}]
(* 3 *)
PermutationCount[{a, a, b, c, c, d}]
(* 180 *)
PermutationCount[{a, b, c}]
(* 6 *)

In the case that you want partial permutations (k-permutations) you will need something more than Multinomial. For that I suggest this function:

kP =
    #2! Product[Sum[\[FormalX]^r/r!, {r, 0, n}], {n, #}],
    {\[FormalX], 0, #2}
  ] &

Which can be formatted in the FrontEnd like this:

enter image description here

Example of use:

lst = {"a", "a", "b", "c", "c", "d"};

kP[Last /@ Tally[lst], 4]


Permutations[lst, {4}] // Length

It can handle large sets:

lst = RandomInteger[500, 2500];

kP[Last /@ Tally[lst], 75]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.