Password consists of 5 characters, these characters can be a digit (0-9) and the letters ABC 26 letters. Each character can be repeated more than once. How many different passwords that have at least one digit and at least one letter?

I tried to think of it this way: $$10 * 26 * 36 ^ 3=12,130,560$$

Because there is at least one letter and one digit and hence have 36 other options ...

According to the book: $$36^5-[10^5+26^5]=48,484,800$$

  • 2
    $\begingroup$ you want to count the numbers of passwords with 5 characters without restrictions it is $36^5$ minus the passwords with 5 letters ($26^5$ such passwords) and minus the passwords with 5 numbers ($10^5$ such passwords). $\endgroup$ – Jennifer Mar 28 '16 at 14:46
  • $\begingroup$ Try to think of the different ways you can get the probability of a certain combination. Two common ways are by getting it directly by counting the number of allowed cases, or by getting it indirectly by starting with the probability of any combination and then subtracting whatever combinations are not allowed. $\endgroup$ – MathInferno Mar 28 '16 at 14:48
  • 1
    $\begingroup$ I think that his question is not, why the second formula is correct, but rather why the first one is wrong. $\endgroup$ – ThorbenK Mar 28 '16 at 14:48
  • $\begingroup$ An other approach would be te consider all the patterns possible : for example LNNLN (where L is a letter and N a number) and for each patter count all the possibilities, it would be an approach similar to your first idea but you have to consider a lot of patterns. $\endgroup$ – Jennifer Mar 28 '16 at 14:51
  • $\begingroup$ And with you calculation you only count the passwords with the following patterns : NLXXX where X can be N or L, so you don't count "abc36" as a legit password for example. $\endgroup$ – Jennifer Mar 28 '16 at 14:58

The total number of sequences of 5 characters is $36^5$. Consider the sequences of 5 characters that are not valid passwords. There are two types of them: the sequences containing only digits ($10^5$ possible sequences) and the sequences containing only letters ($26^5$ possible sequences). This explains the (right) answer of the book.

Coming back to your answer, the problem is that you are counting this way the number of sequences having a digit in the first position and a letter in the second position.

Edit. If you want to use your method, you should decompose the cases as follows. Let $D$ denote a digit, $L$ a letter and $S$ any symbol. Then you may have the following mutually disjoint cases $$ LDSSS, LLDSS, LLLDS, LLLLD, DLSSS, DDLSS, DDDLS, DDDDL $$ leading to the number $$ 26 \times 10 \times 36^3 + 26^2 \times 10 \times 36^2 + 26^3 \times 10 \times 36 + 26^4 \times 10 + 10 \times 26 \times 36^3 + 10^2 \times26 \times 36^2 + 10^3 \times 26 \times 36 + 10^4 \times 26 = 48484800 $$ If you know automata theory, it is similar to finding the complement of a regular expression.

  • $\begingroup$ I think that his question is not, why the second formula is correct, but rather why the first one is wrong. $\endgroup$ – ThorbenK Mar 28 '16 at 14:50
  • $\begingroup$ I was editing my answer as you were writing your comment... $\endgroup$ – J.-E. Pin Mar 28 '16 at 14:53
  • $\begingroup$ Thank you! I understand how work the second answer and why my answer is not exact. But how do I fix my answer be correct? $\endgroup$ – BAM Mar 28 '16 at 15:16

Either you calculate the possible ways by counting ($1N-4L$), ($2N-3L$), ($3N-2L$), ($4N-3L$) and you sum them. or you calculate the case where all situation could happen and subtract the the two cases where all are digits(no litter) and all litter(no digit) from the total case.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.