# Number of possible $7$-digit PIN codes

What is the number of all possible $7$-digit PIN codes if

1) all the digits in a code should be different?

2) all the digits should be different and the first digit should be greater than the second one?

3) the sum of the digits should be $9$? (digits may repeat)

I think the answer for the first question is $604800$

• First is correct (assuming your digits are $\{0,1,\cdots,9\}$. For the second: Hint: given any solution to the first, either it also works for the second or it would work if you flipped the two first digits. – lulu Sep 24 '16 at 16:36
• Thanks for your answer. I think the answer for the second question should be 302400. But as for the third one, I don't know how to calculate it. Could you give me a hint? – Mary Sep 25 '16 at 8:00
• I agree with $302400$. For the last, you could use Stars and Bars or, if you want to do it by hand, work off the maximum digit. Thus, if max $=9$ then we must have $9$ and $6$ zeroes so there are $7$ cases, if max $=8$ then we get $7\times 6$ cases, and so on. Tedious, but not difficult. – lulu Sep 25 '16 at 9:49

For question 3, we can think of any $7$-digit number whose digits sum to $9$, for example $4011021$, as:

$$****||*|*||**|*$$

with each digit converted to that number of stars (possibly no stars!); and each digit separated by bars.

So we are counting the number of ways of choosing 7-1 = 6 bars from 6+9 positions. That value is

$${15 \choose 9} = 5005$$.

HSE-ICEF, 1st course, 3rd Home Assignment?

• 1) $604800$
• 2) $302400$
• 3) $5005$

But, probably, it's too late.

The third one consists of the ordered partitions of $9$ into at most $7$ parts when taken over $7$ digits.

The partitions of $9$ that qualify are therefore $$9,\\81,\\72,711,\\63,621,6111,\\54,531,522,5211,51111,\\441,432,4311,4221,42111,411111,\\333,3321,33111,3222,32211,321111,3111111,\\22221,222111,2211111$$

Each one is calculated by taking the multinomial $\dbinom{7}{k_i}$ where each $k_i$ is the number of elements in each distinct digit group (not forgetting the zero digits), so, for example, for $4311$ becomes $\dbinom{7}{1,1,2,3}=\dbinom{7!}{1!1!2!3!}=7\cdot 5\cdot 4\cdot 3=420$.