0
$\begingroup$

There is a random password that only contains $7$ digits and has at most one $5$ in the entire password. Find the total number of passwords that can be generated using this condition.

I believe that the logic to solve this problem would be as follows:

If at most one digit out of the seven can contain the number $5$, this implies that the sample set of digits to choose from would be $[0,1,2,3,4,5,6,7,8,9]$. I can pick any number from this sample set for any one digit, since my overall password may or may not contain the number $5$. Therefore, the number of combinations for this digit would be $10C1$. For the remaining six digits, since I can't reuse the number $5$, I reduce the sample set to $[0,1,2,3,6,7,8,9]$, which implies $9C6$. So, the final answer would be $10C1$ multiplied by $9C6$, which implies a $7$-digit password.

However, there is also another way to look at this. We could either have $5$ inside the password or we could not, and that would be represented as $9C7 + (10C1 \cdot 9C6)$. Where $9C7$ implies the sample set is without $5$ and pick any random number from that sample set and the other end of the bracket is the same as explained above.

The confusion for me here is which of these two approaches is the correct answer if either, and what approach someone else would take when it comes to issues like this.

$\endgroup$
6
  • $\begingroup$ Is repetition of digits permitted? You seem to be assuming that the digits must be distinct, but I do not see that condition stated in the question. $\endgroup$ Oct 17, 2023 at 10:23
  • $\begingroup$ Oh I am sorry I couldn't figure out how to write 10 Choose 3 The C here doesn't imply combinations or permutations rather it's just a general representation of the logic for the foundation of the issue. Obv repetition is allowed for everything apart from 5 $\endgroup$ Oct 17, 2023 at 10:25
  • $\begingroup$ Welcome to MathSE. This MathJax tutorial explains how to typeset mathematics on this site. $\endgroup$ Oct 17, 2023 at 10:30
  • $\begingroup$ If repetition of digits is permitted, then you have nine choices for each digit that is not a $5$. There are two cases: no fives appear, or exactly one five appears. If exactly one five appears, you need to choose its position, then fill each of the remaining positions with a digit other than $5$. With that in mind, please make another attempt to solve the problem. $\endgroup$ Oct 17, 2023 at 10:34
  • $\begingroup$ I have given this another go in the past few days and would like some input. So for starters, since it is a password the order obviously matters for starters as pointed out by Taussig. There are two cases here either it has 5 or it doesn't. If it does we have $\frac{7!}{(7-1!)}$ ways of arranging it. which means $7$ Let's now consider the rest of the digits of the password. The sample size decreases to $9$ since we can't re-use the 5 so we essentially have $9^6$ ways of arranging the other digits. this implies the final answer is $(7*9^6)+9^7$ Can you please provide feedback. $\endgroup$ Oct 21, 2023 at 4:20

1 Answer 1

1
$\begingroup$

Your answer in the comments is correct. If the password does not contain a $5$, there are nine choices for each of the seven positions, so there are $9^7$ such passwords. If the password contains exactly one $5$, there are seven ways to place the $5$ and nine choices for each of the remaining six positions, so there are $7 \cdot 9^6$ such passwords. Since the two cases are mutually exclusive and exhaustive, there are $$9^7 + 7 \cdot 9^6$$ seven-digit passwords that contain at most one $5$.

With regard to your initial attempt, note that $$\binom{n}{k} = \frac{n!}{k!(n - k)!}$$ is the number of $k$-element subsets of a $n$-element set.

Had you been asked to find the number of seven-digit passwords with distinct digits in which the digit $5$ appears at most once, we could proceed as follows.

  • If $5$ does not appear, select which seven of the nine other decimal digits will appear, then arrange those seven distinct digits in the seven positions.
  • If $5$ appears exactly once, choose in which of the seven positions it will appear, select which six of the nine other decimal digits will appear in the password, then arrange those six distinct digits in the remaining six positions.

If $5$ does not appear in the password, there are $\binom{9}{7}$ ways to select seven of the nine other decimal digits and $7!$ ways to arrange those distinct digits in the seven positions. If $5$ does not appear, there are seven ways to select its position, $\binom{9}{6}$ ways to select six of the other nine decimal digits to fill the remaining six positions, and $6!$ ways to arrange them in those positions. Since these two cases are mutually exclusive and exhaustive, there are $$\binom{9}{7}7! + \binom{7}{1}\binom{9}{6}6!$$ seven-digit passwords with distinct digits in which $5$ appears at most once.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .