Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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? – Nasser Dec 26 '13 at 6:22
@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. – ubpdqn Dec 26 '13 at 13:12

You can count the permutations using Multinomial:





{3, 180, 6}

share|improve this answer

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 *)
share|improve this answer

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]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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