0
$\begingroup$

For example, if n = 3, there are 10 possibilities:
111, 222, 333, 112, 113, 221, 223, 331, 332, 123

For n = 4, there are 35 possibilities;
For n = 5, there are 126 possibilities;
For n = 6, there are 446 possibilities;
For n = 7, there are 1569 possibilities;

I have found a way to calculate it, but it seems that I am going the long way. It goes like this:
For n = 5, find all the possible partitions, where each element is the length of equal digit sets in the number:
(5) -> 11111, 22222...
(4,1) -> 11112, 11113...
(3,2) -> 11122, 11133...
(3,1,1) -> 11123, 11124...
(2,2,1) -> 11223, 11224...
(2,1,1,1) -> 11234, 11235...
(1,1,1,1,1) -> 12345
Then, to calculate the number of combinations m of a given partition with k elements, I have found the following pattern: $$ m = {n!\over(n-k)!\prod_{i=1}^n s_i!} $$ Where $s_i$ is the number of sets of length i. Back to the example where n = 5, the number of combinations for each partition is:
(5) -> 1 set = 5!/(5-1)! = 5!/4! = 5
(4,1) -> 2 sets = 5!/(5-2)! = 5!/3! = 20
(3,2) -> 2 sets = 5!/(5-2)! = 5!/3! = 20
(3,1,1) -> 3 sets, 2 sets of length 1 = 5!/(5-3)!/2! = 5!/2!/2! = 30
(2,2,1) -> 3 sets, 2 sets of length 2 = 5!/(5-3)!/2! = 5!/2!/2! = 30
(2,1,1,1) -> 4 sets, 3 sets of length 1 = 5!/(5-4)!/3! = 5!/3! = 20
(1,1,1,1,1) -> 5 sets, 5 sets of length 1 = 5!/(5-5)!/5! = 5!/5! = 1
Finally, sum it all: 5+20+20+30+30+20+1 = 126

Is there an easier and more scalable way?

  • 0
    For $n=3$ what about $121$ or $122$ or many of the other ones you didn't write out... You say "order is irrelevant" so these are considered the same outcome as $112$ and $221$ in your list? Why bother describing these as "n-digit numbers" then? Why didn't you write them all in strictly increasing order to make it cleaner?2017-02-04
  • 1
    Let $x_1$ be the number of $1$'s used in the number. Let $x_2$ be number of $2$'s, etc... then you have the system $\begin{cases} x_1+x_2+\dots+x_n=n\\0\leq x_i\end{cases}$. Apply [stars and bars](https://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics)) to conclude that there are $\binom{2n-1}{n-1}$ arrangements.2017-02-04

0 Answers 0