Count permutations of [1, 1, 1, 2, 2, 3, 3, 4, 5] with length 6 How can I count number of permutations such as:
[1, 1, 1, 2, 2, 3]
[1, 2, 1, 3, 2, 4]
[1, 1, 1, 2, 2, 5]
...
So I have:
'1' x 3
'2' x 2
'3' x 2
'4' x 1
'5' x 1
So permutation valid if it contains $\le3$ of '1' and $\le2$ of '2' and and $\le2$ of '3' and $\le1$ of '4' and $\le1$ of '5' and it's length is 6.
I've counted them on Python with filtering and the answer is 3630. But how it works?
Thanks!

I believe you are forced to sum mutually exclusive and exhaustive possibilities.
I suggest defining $N(a,b)$ as the number of permutations having $a$ "1"'s and $b$ other doubles. Then ...
$$N(a,b) = \binom 2 b \cdot \frac{6!}{a!(2!)^b}$$
and
$$ N_{tot} = N(0,2)+N(1,2)+N(1,1)+N(2,2)+N(2,1)+N(2,0)+N(3,1)+N(3,0) $$
* EDIT *
I my expression gave the number of permutations given a specific combination of "single" extra numbers (extra means not including 1 or any doubles )
there will be $4-b$ "single" numbers from which we must choose $6-a-2b$
So my formula above should be amended to read
$$N(a,b) =\binom{4-b}{6-a-2b}\binom 2 b \cdot \frac{6!}{a!(2!)^b}$$
Evaluating the formula ...
$$ \begin{eqnarray*} 
N_{tot} =&  \binom 2 2 \binom 2 2 \frac{6!}{(2!)^2} 
+ \binom 2 1 \binom 2 2 \frac{6!}{(2!)^2} 
+ \binom 3 3 \binom 2 1 \frac{6!}{ 2!}
\\+ &\binom 2 0 \binom 2 2 \frac{6!}{2! (2!)^2}  
+ \binom 3 2 \binom 2 1 \frac{6!}{ 2! (2!)} 
+ \binom 4 4 \binom 2 0 \frac{6!}{ 2! } 
\\+ & \binom 3 1 \binom 2 1 \frac{6!}{ 3! (2!)} 
+ \binom 4 3 \binom 2 0 \frac{6!}{ 3! } 
\end{eqnarray*}$$
$$ =(1)(1)(180)+(2)(1)(180)+(1)(2)(360)+ (1)(1)(90) \\+ (3)(2)(180) + (1)(1)(360) + (3)(2)(60) +(4)(1)(120)   $$
$$ =180+360+720+90+1080+360+360+480   = 3630$$
