Number of permutations without leading zeroes.

4.9k Views Asked by At

Suppose I have a number $120$. I want to find the number of permutations its digits can have to form other numbers except the ones with leading zeroes.

For example, its permutations can be $120, 210, 201, 102, 012, 021$, which is $6$ or $n!$. However, I require $4$ (excluding the values with leading zeroes).

How can this be generalized to larger numbers?

7

There are 7 best solutions below

0
On BEST ANSWER

In general, if you have a number with $n_0$ $0$'s, $n_1$ $1$'s, $n_2$ $2$'s, and so on, the number of permutations of these is $$ \frac{(n_0+n_1+n_2+n_3+n_4+n_5+n_6+n_7+n_8+n_9)!}{n_0!n_1!n_2!n_3!n_4!n_5!n_6!n_7!n_8!n_9!}. $$ What this does is to count all the permutations as if all the numbers were different, and then divides by the ways to rearrange the repeats to remove double counting. The problem with is is that it also allows leading $0$'s. Our goal will be to subtract the leading $0$'s from this count.

If $n_0=0$, then there are no zeros, so this count is the total count in this case. If $n_0\not=0$, we place one of the zeros in the first position, leaving $n_0-1$ zeros for the rest of the number. Then, we arrange the remaining numbers just as before. So, we have $$ \frac{((n_0-1)+n_1+n_2+n_3+n_4+n_5+n_6+n_7+n_8+n_9)!}{(n_0-1)!n_1!n_2!n_3!n_4!n_5!n_6!n_7!n_8!n_9!}. $$ ways for the leading entry to be $0$.

Subtracting the second expression from the first gives the count you're looking for.

Examples:

  • In your first example, $120$, $n_0=1$, $n_1=1$, $n_2=1$, and all other $n_i$'s are $0$. Therefore, the number of possible permutations is $$ \frac{(1+1+1)!}{1!1!1!}=3!=6. $$ On the other hand, the number of numbers that start with $0$ is $$ \frac{((1-1)+1+1)!}{(1-1)!1!1!}=\frac{2!}{0!1!1!}=2!=2. $$ Subtracting these two gives $6-2=4$ ways to write a number without leading $0$'s

  • In your second example, $5500$, we have that $n_0=2$, $n_5=2$, and all other $n_i$'s are $0$. Therefore, the total number of permutations is $$ \frac{(2+2)!}{2!2!}=\frac{4!}{2!2!}=\frac{24}{2\cdot 2}=6. $$ On the other hand, the number of permutations starting with zero is $$ \frac{((2-1)+2)!}{(2-1)!2!}=\frac{3!}{1!2!}=\frac{6}{1\cdot 2}=3. $$ The difference is $3$, which is the number of permutations that don't start with $0$.

0
On

To the first place, you can put $2$, to the second you can put the remaining $2$ and to the last place the remaining $1$. So $2*2*1=4$.

6
On

How about finding all the permutations and then subtracting those with leading zeros? i.e.,

$$3!-2!=4$$

In general, for n-digit number with 1 zero,

$$n!-(n-1)!=(n-1)*(n-1)!$$

0
On

Suppose you have $a_k$ $k$'s, for each digit $0\le k\le9$, and $a_0+a_1+\cdots+a_9=n$. Then the number of different $n$-digit numbers with no leading $0$'s that can be made with the specified digits is

$${n-1\choose a_0}{n-a_0\choose a_1}{n-a_0-a_1\choose a_2}\cdots{n-a_0-a_1-\cdots-a_{k-1}\choose a_k}\cdots{a_9\choose a_9}$$

For example, if you start with $00011377$, then $a_0=3$, $a_1=2$, $a_3=1$, and $a_7=2$ (and all other $a_k$'s are $0$), so we get $n=3+2+1+2=8$ and thus the number of $8$-digit numbers is

$${7\choose3}{8-3\choose2}{8-3-2\choose1}{8-3-2-1\choose2}={7\choose3}{5\choose2}{3\choose1}{2\choose2}=35\cdot10\cdot3\cdot1=1050$$

The key here is to place the $0$'s first. As long as they avoid the first position, they can go anywhere; once they're in place, the other digits go into any position still available, including the first position.

If you like, the formula can be rewritten more briefly as

$${n-1\choose a_0}{(n-a_0)!\over a_1!a_2!\cdots a_9!}$$

0
On

Suppose the figure $i$ occurs $n_{i}$ times in your original number $A$, and let $n = \sum_{i=0}^{9} n_{i}$.

The total number of permutations (including those with leading zeroes) is the multinomial coefficient $$ \frac{n!}{\prod _{i=0}^{9} n_{i}!}. $$ If $n_{0} = 0$, that's it.

If $n_{0} \ge 1$, consider one of the permutations starting with zero. By removing that zero we obtain a permutation of the number obtained from $A$ by removing one zero, of which there are $$ \frac{(n-1)!}{(n_{0} - 1)! \prod _{i=1}^{9} n_{i}!}. $$ So in this case the formula should be $$ \frac{n!}{\prod _{i=0}^{9} n_{i}!}- \frac{(n-1)!}{(n_{0} - 1)! \prod _{i=1}^{9} n_{i}!} = \frac{(n-1)! (n - n_{0})}{\prod _{i=0}^{9} n_{i}!}. $$

0
On

Let us have a number with $n_0$ $0$s, $n_1$ $1$s, and so on.

Then the total number of digits will be $\sum n_i$.

On the first place you can place any digit except $0$, so you have $n_1+n_2+\dots+n_9=\left(\left(\sum n_i\right)-n_0\right)$ possible ways to choose the first number.

The rest $\sum n_i$ digits can be filled in $\left(\left(\sum n_i\right)-1\right)$ can be filled in $\left(\left(\sum n_i\right)-1\right)!$ ways, by the elementary formula.

However there are repeating digits, so we divide by $n_0\cdot n_1\cdot n_2\cdot\;\cdots\;\cdot n_9$.

This gives us

$$\left(\left(\sum^9_{i=0}n_i\right)-1\right)!\times\left(\left(\sum^9_{i=0}n_i\right)-n_0\right)\over\prod^9_{i=0}n_i!$$

0
On

Permute elements from the set {$0,1,2$} without having the $0$ leading digits arrangements:

Generally, let's consider the case with no restrictions...

You have $3$ spots, and the cardinality of the set is $3$ so the total number of permutations with no restriction would be $3P3 = 3! = 3*2*1 = 6$

Now Let's put some rules to follow your requirement:

First place could have $2$ different possibilities namely $1$ or $2$, then in the second we are left up with $2$ more digits, $0$ and either $1$ or $2$, and in the final one, you will end up with only $1$ digit left, and that would give $2*2*1$ equal to $4$ arrangements without leading zeros.

Similarly, you can say $3!$ as the total number of arrangements and exclude them from the current $4$ possibilities that we just calculated, and it will give you the number $2$ arrangements having leading zero.