# Counting Password sequence.

Each user on a computer system has a password, which is six to eight characters long, where each character is an uppercase letter or a digit. Each password must contain at least one digit. How many possible passwords are there?

I am solving this in following way:

D => count(Digit 0 to 9) = 10

• => count(Digit ∪ letters) = 26 + 10 = 36

Passwords of length 6 with at least one digit = _ _ _ _ _ _ => * D * * * * => 10 x 365

Passwords of length 7 with at least one digit = _ _ _ _ _ _ => * * D * * * * => 10 x 366

Passwords of length 8 with at least one digit = _ _ _ _ _ _ => D * * * * * * * => 10 x 367

So Total sequences allowed = 10 x 365 + 10 x 366 + 10 x 367 => 806014126080

But answer is : 2,684,483,063,360 How?

• The digit that we must include can go anywhere within the password. Your calculation only considers the case where the digit must go to a fixed location. Even so, you will have over counted. It is easier to calculate the number of passwords which only include letters, and subtract this from the total number of passwords with no restrictions – Jihoon Kang Oct 1 '17 at 4:36
• Please use MathJax to format your posts. – gen-z ready to perish Oct 1 '17 at 6:11
• Your answer counts each password with $k$ digits $k$ times, once for each way of designating a particular digit as the one that the password must include. – N. F. Taussig Oct 1 '17 at 8:18

## 1 Answer

For passwords of length $6$ with at least one digit you put $10*36^5$. So you chose one digit and you chose $5$ other characters but you didn't choose the order they go in. You could add in a $5!$ to account for that but then you'd have to deal with the fact that you've double counted passwords with more than one digit. All in all it's not the ideal way to approach the problem.

Sometimes if you want to count a subset it's easier to count the whole set and count the complement. The difference is then the count of your subset.

If you want passwords that are $n$ characters long and contain at least one digit then take the total number of $n$ character long passwords and subtract out the number of $n$ character long passwords that don't contain a digit. So $36^n - 26^n$.

Now sum that up for $n = 6, 7, 8$ and you'll get the desired answer.