Combinatorics – Stars and Bars Problem

combinatorics

How many 4 digit numbers have a sum of 9?

I converted that into:
How many ways can you rearrange 3 stars and 9 bars?
But the first one has to be a number so it's actually:
How many ways can you rearrange 3 stars and 8 bars?
I can convert it but I forgot how to solve the stars and bars problem? Can someone explain how to solve a converted stars and bars problem without giving me the answer to this question? Thanks.

Best Answer

If a four-digit number has a digit sum of $9$, then you can consider $9$ stars and $3$ bars, like you say. This means there are $12$ total slots, and choosing the $3$ slots in which the bars go is sufficient for counting the number of ways to arrange them. This is the binomial coefficient $$\binom{12}{3}$$

But we've overcounted (as you noticed), so we need to subtract the number of numbers that we counted that started with zeroes. These are exactly the three-digit numbers (including those with leading zeroes) whose digit sum is nine. We can convert this to $9$ stars and $2$ bars, so our final answer should be

$$\binom{12}{3}-\binom{11}{2}$$


You can also do this problem the way you did it, with $8$ stars and $3$ bars. Why is the answer the same if you do it this way? In other words, why is this true?

$$\binom{12}{3}-\binom{11}{2}=\binom{11}{3}$$

Can you generalize it? After thinking about this you might want to read about Pascal's rule.

Related Question