How many numbers don’t contain the digit 9?

Let’s see how many numbers from 0 to 10^n-1 don’t contain the digit 9.

For this kind of problem a computer scientist will most probably try to implement a sophisticated algorithm, a mathematician will try to find a direct formula, and a physicist will give an approximated value.

I’ll choose the math approach and instead of counting we can think to numbers as an array of digits. Imagine n positions that can be filled with digits from 0 to 9. The digits with value 0 from the front can be ignored. For example 00127 represent actually then number 127.

Considering the above each of the n positions can be filled with a value from 0 to 8 because we don’t want the digit 9. This means that we have 9 ways to fill each position, resulting a total of 9^n numbers having up to n digits and not containing the digit 9. We also counted the number 0 because it appears when all the n positions are filled with digit 0.

This entry was posted in Math. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s