[Math] How many passwords with maximum length $8$ can be formed from upper case letters, lower case letters, digits, or hyphens

combinatorics

The password for the security access to a vault is a multi-character string consisting of a combination of uppercase letters, lowercase letters, digits or hyphens. The rule on creating the password is that the first character in the string must be either a digit or lowercase letter or uppercase letter. The password length has maximum characters of eight (8). How many different combinations of passwords are there?

Here Hyphen is making problem to solve . How I can fix it?

Best Answer

There are $63$ ($26 + 26 + 10 +1$) allowed characters. Only one is forbidden on the first place (hyphen).

So there are 62 passwords of length 1.

There are $62 \times 63$ passwords of length 2.

There are $62 \times 63 \times 63$ passwords of length 3, etc.

Now sum up to and including length 8 (and use a formula for a finite sum of this type, if you know it).

To expand on the last bit: note that for $a \neq 1$: $1 + a + a^2 + \ldots + a^k = \frac{a^{k+1}-1}{a-1}$ (proof: multiply both sides by $a-1$). In the sum, get the 62 out, and use this result to see we can write is directly as $63^8 - 1$.

The latter suggests a direct proof of that fact. Consider all sequences of all 63 allowed characters of length 8. Remove all consecutive hyphens from the start onwards. This gives all allowed passwords exactly once. The only problem is the all hyphen word, which would result in the empty password (which I assume is not allowed). Hence $63^8 - 1$.