How do I calculate the number of permutations for this list [1, 2, 3, 1, 2, 3, 1, 2, 3]?

229 Views Asked by At

How do I calculate the number of permutations for the list, $$[1, 2, 3, 1, 2, 3, 1, 2, 3]?$$ I thought the number of permutations is given by $$\frac{9!}{3\times3!}.$$ However, I created a python code to test this and it suggests that the number of permutations is much less than this. Can you see where I have gone wrong? Is my formula incorrect or have I made a mistake in the code?

Here is the python code:

from itertools import permutations
from math import factorial

perm = permutations([1, 2, 3, 1, 2, 3, 1, 2, 3])

# Generate all permuations based on index number
mylist = list(perm)
print('The total number of permuations based on cell index =', len(mylist))
print('Note that 9! =', factorial(9))

# Remove all repeated entries based on cell value
mylist = list(dict.fromkeys(mylist))
print('The total number of permuations based on cell value is ', len(mylist))
print('Note that 9! / (3 * 3!) = ', int(factorial(9) / (3 * factorial(3))))

Here is the output:

The total number of permuations based on cell index = 362880
Note that 9! = 362880
The total number of permuations based on cell value is  1680
Note that 9! / (3 * 3!) =  20160
2

There are 2 best solutions below

0
On BEST ANSWER

The denominator should not be $3\times 3!$ but $(3!)^3$.

Namely, you start with a situation where you distinguish all the $1$'s, all the $2$'s and all the $3$'s, which gives you $9!$ permutations, but then need to divide by $3!$ three times (to account for the fact that you don't distinguish them), which is effectively dividing by $(3!)^3$.

2
On

The denominator should be $(3!)^3$ and not $3\cdot 3!$. This will give you the right value $1680$.