What's the direct way of counting number of strings with at least one number?

271 Views Asked by At

The number of strings of six characters (uppercase alphabets and numbers) out of which at least one character should be a number. This problem is often solved like this:

All strings of $6$ digits made up of uppercase characters and numbers $= 36^6$.

All strings of $6$ digits with only uppercase characters = $26^6$.

Answer $= 36^6 - 26^6 = 1867866560$.

I was searching for a way to do this not through the subtraction way as above.

2

There are 2 best solutions below

4
On BEST ANSWER

The subtraction way is definitely the right approach. If you really wanted to do it a different way the following would work.

If the first digit occurs in position 1, there are $10\times 36^5$ options (digit followed by anything). If the first digit is in position 2, there are $26\times10\times 36^4$ options (letter, digit, then anything), and so on, so the answer is

$$10\times 36^5+26\times10\times36^4+26^2\times10\times36^3+26^3\times10\times36^2+26^4\times10\times36+26^5\times 10.$$

0
On

The number of upper case alphanumeric strings of length $6$ with at least one numeral is $$\sum_{k=1}^6\binom6k10^k26^{6-k}$$ where the term $\binom6k10^k26^{6-k}$ is the number of strings containing exactly $k$ numerals and $6-k$ upper case letters. Without the requirement of at least one numeral, the total number of strings is $$\sum_{k=0}^6\binom6k10^k26^{6-k}=(10+26)^6=36^6$$ by the binomial theorem, so the number of strings with at least one numeral is $$\sum_{k=1}^6\binom6k10^k26^{6-k}=\sum_{k=0}^6\binom6k10^k26^{6-k}-\binom6010^026^6=36^6-26^6.$$

Now, if you want the number of strings with at least two numerals, that is given "directly" by the sum $$\sum_{k=2}^6\binom6k10^k26^{6-k},$$ Or to make the calculation a little easier we can rewrite it as $$\sum_{k=0}^6\binom6k10^k26^{6-k}-\sum_{k=0}^1\binom6k10^k26^{6-k}=36^6-26^6-6\cdot10\cdot26^5.$$