Calculating permutations for a specific password policy The security researcher Troy Hunt posted an example of an obscure password policy and I've been trying to figure out how to calculate the possible permutations 
(Source: https://twitter.com/troyhunt/status/885243624933400577)
The rules are:


*

*The password must contain $9$ numbers (and only $9$ numbers)

*It must include at least $4$ different numbers

*It cannot include the same number more than three times


I understand the basic permutations will be $10^9$ ($0-9$ nine times) $= 1,000,000,000$
What I don't understand is how you factor in the reduction in permutations by enforcing $4$ different numbers and limiting repeats to $3$.

A brute force solution:
Nine numbers:  Each number appears exactly once.  We choose nine of the ten digits, then arrange the selected digits. 
$$\binom{10}{9}9!$$
Eight numbers:  We must use of the ten digits twice.  We choose that digit, choose two of the nine locations for that number, choose seven of the other nine numbers, then arrange them in the seven open positions.
$$10\binom{9}{2}\binom{9}{7}7!$$
Seven numbers:  There are two ways of partitioning $9$ into seven positive integers.
\begin{align*}
9 & = 3 + 1 + 1 + 1 + 1 + 1 + 1\\
  & = 2 + 2 + 1 + 1 + 1 + 1 + 1
\end{align*}
One number appears three times, and six appear once each:  We choose which of the ten digits appears three times, choose three of the nine positions for the numbers, select six of the other nine numbers, and arrange them in the six open positions.
$$10\binom{9}{3}\binom{9}{6}6!$$
Two digits appear twice, five numbers appear once each:  We choose which two of the ten digits will appear twice, choose two of the nine positions for the smaller of those numbers, choose two of the seven remaining open positions for the larger of those numbers, choose five of the eight remaining numbers, and arrange them in the five open positions.
$$\binom{10}{2}\binom{9}{2}\binom{7}{2}\binom{8}{5}5!$$
Six numbers:  We partition $9$ into six positive integers.
\begin{align*}
9 & = \color{red}{4 + 1 + 1 + 1 + 1 + 1}\\
  & = 3 + 2 + 1 + 1 + 1 + 1\\
  & = 2 + 2 + 2 + 1 + 1 + 1
\end{align*}
The partition shown in red is prohibited since no number may appear more than three times.
One number appears three times, another number appears twice, and four numbers appear once each:  We choose the number that appears three times, choose three of the nine positions for that number, choose which of the nine remaining numbers appears twice, choose two of the six remaining positions for that numbers, choose four of the eight remaining numbers, and arrange them in the four remaining positions.
$$10\binom{9}{3} \cdot 9\binom{6}{2}\binom{8}{4}4!$$
Three numbers appear twice each, and three numbers appear once each:  We choose three numbers to appear twice each, choose two of the nine positions for the smallest of those numbers, choose two of the seven remaining positions for the next smallest of those numbers, choose two of the five remaining positions for the largest of those numbers, choose three of the seven remaining numbers to appear once each, and arrange them in the the three remaining positions.
$$\binom{10}{3}\binom{9}{2}\binom{7}{2}\binom{5}{2}\binom{7}{3}3!$$ 
We can partition $9$ into exactly five numbers in the following ways:
\begin{align*}
9 & = \color{red}{5 + 1 + 1 + 1 + 1}\\
  & = \color{red}{4 + 2 + 1 + 1 + 1}\\
  & = 3 + 3 + 1 + 1 + 1\\
  & = 3 + 2 + 2 + 1 + 1\\
  & = 2 + 2 + 2 + 2 + 1
\end{align*}
We can partition $9$ into exactly four numbers in the following ways:
\begin{align*}
9 & = \color{red}{6 + 1 + 1 + 1}\\
  & = \color{red}{5 + 2 + 1 + 1}\\
  & = \color{red}{4 + 3 + 1 + 1}\\
  & = \color{red}{4 + 2 + 2 + 1}\\
  & = 3 + 3 + 2 + 1\\
  & = 3 + 2 + 2 + 2
\end{align*}
The partitions shown in red are prohibited by the constraint that no digit can appear more than thrice.  
Can you continue?
