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

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.

• I am afraid that you won't get anything simpler than this. – Nathanael Skrepek Apr 6 '17 at 9:01
• I don't want a simpler solution, I am just asking for one – Sanjay Apr 6 '17 at 9:02
• add up the 1,2,3,4,5,6 number cases (obviously more complicated) – Cato Apr 6 '17 at 9:15

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

• I only understand this till option 1. I mean, why can't it be like this : 10x36^5 (number at first position), 36 x 10 x 36^4 (when number is at second). They all should be 10 x 36^5 why not? – Sanjay Apr 6 '17 at 9:08
• The second case isn't "digit in second", it's "the first digit is in second", so you need a letter, then a digit, then anything. If you count "digit in first" then "digit in second", you've counted all the strings that start with two digits twice. – Especially Lime Apr 6 '17 at 9:13
• @sanjay - the string 12AAAA would be counted by both of your cases, that is to say, double counted (or multiple counts) - try it with 3 character string, 1 letter and 1 number - you'll see how it double coubnts – Cato Apr 6 '17 at 9:13
• @Cato That's the point I was missing. Thanks. – Sanjay Apr 6 '17 at 9:27

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