## Trending News

# What is the chance that sum of the digits of a 5 digits number be 20?

we have a random 5 digits number. What is the chance that sum of the digits be 20?

for example 90461

### 2 Answers

- M3Lv 78 years agoFavorite Answer
using the "stars and bars" formula with inclusion-exclusion, (as a digit can't be 10 or more)

# = 24c4 - 5c1*14c4 + 5c2*4c4 = 5631

but this will include #s with 0 as 1st digit or 1st 2 digits, numbering

(23c3 - 4c1*13c3 +4c2*3c3) - (22c2 - 3c1*12c2 + 3c2*2c2) = 596

Pr = (5631-596)/9000 = 0.5594 <--------

manual check for 3 digit #s

---------------------------------

992:3

983:6

974:6

965:6

884:3

875:6

866:3

776:3 = 36 = (22c2 - 3c1*12c2 + 3c2*2c2) , as expected

.

- 8 years ago
M3 has the right idea, but his answer is wrong.

The correct answer is:

((24c4 - 5c1*14c4 + 5c2) - (23c3 - 4c1*13c3 + 4c2)) / (99999-9999) = 4998 / 90000 = 0.0555333 ...

There were two problems with M3's answer. First, he needed to divide by the count of 5-digit numbers, which is 90000, not 9000. Second, he incorrectly computed the count of 5-digit numbers whose digits sum to 20. It should be 4998, not 5035.

I checked this answer using two different programming methods. I coded up two solutions in Java. One uses dynamic programming to efficiently compute a recurrence relation. The other uses a simple, brute force solution that anyone who is remotely familiar with programming can tell you is correct.

Brute force solution:

int count = 0;

for (int i=10000;i<=99999;i++) {

int num = i;

int digits = 0;

while (num > 0) {

digits += num%10;

num /= 10;

}

if (digits == 20) ++count;

}

System.out.println("Count of 5-digit numbers whose digits sum to 20 = " + count);

Dynamic programming recurrence:

f(i,j) = count of numbers of length i whose digits sum to j

base case: f(1,j) = (1 if j <= 9 and 0 otherwise)

recursive case (where i > 1): f(i,j) = sum over k in {0,1,...,9} of f(i-1,j-k)

Then the final answer is the sum over k in {1,...,9} of f(4,k) so that we skip answers whose first digit is 0.

Source(s): B.Sc. math, 10 years programming.