[Math] Number of possible $7$-digit PIN codes

combinatorics

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$

Best Answer

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$$.