Passcode with Restrictions Question

73 Views Asked by At

I have a problem regarding how many passcodes can be generated with these parameters:

  • Five digit code
  • Two of the digits are odd
  • Zeros can't be used
  • Digits can be repeated

One approach I tried was to do $5 \cdot 5 \cdot 4 \cdot 4 \cdot 4$ and then multiply by how many ways the digits can be rearranged, but that doesn't work because sometimes the digits will repeat.

I could break it down into cases such as all no repeats multiplied by how many ways the digits can be rearranged ($5 \cdot 4 \cdot 4 \cdot 3 \cdot 2 \cdot 5!$), then look at only the odd digits are repeated ($5 \cdot 1 \cdot 4 \cdot 3 \cdot 2 \cdot 5!/2!$), etc.

I guess my question is if there is a solution that is more elegant than the case-by-case solution.

2

There are 2 best solutions below

0
On

Your $5\cdot 5 \cdot 4 \cdot 4 \cdot 4$ would be the number of codes with the odd numbers first and second. Now multiply by the number of ways to choose the locations of the odd digits. You are keeping the odd and even digits in the order you generated them.

0
On

There is no need to break the problem down into separate cases. We can select two of the five positions for odd numbers in $\binom{5}{2}$ ways, fill each of these positions with an odd number in $5$ ways, and fill each of the remaining three positions with a nonzero even number in $4$ ways, giving $$\binom{5}{2}5^24^3 = 16000$$ possible passcodes.

We can verify this result by considering the six cases that result from considering repetitions. They are:

  1. One odd digit is used twice and one even digit is used three times.
  2. One odd digit is used twice, one even digit is used twice, and a different even digit is used once.
  3. One odd digit is used twice and three even digits are each used once.
  4. Two odd digits are each used once and one even digit is used three times.
  5. Two odd digits are each used once, one even digit is used twice, and a different even digit is used once.
  6. Two odd digits are each used once and three even digits are each used once.

One odd digit is used twice and one even digit is used three times: There are five ways to select the odd digit that is used twice, four ways to select the even digit that is used thrice, and $\binom{5}{2}$ ways to select the positions of the odd digits. Hence, there are $$\binom{5}{1}\binom{4}{1}\binom{5}{2} = 200$$ such passcodes.

One odd digit is used twice, one even digit is used twice, and a different even digit is used once: There are five ways to select the odd digit that is used twice, four ways to select the even digit that is used twice, and three ways to select the even digit that is used once. There are $\binom{5}{2}$ ways to select the positions of the odd digit that is used twice and $\binom{3}{2}$ ways to select the positions of the even digit that is used twice. Hence, there are $$\binom{5}{1}\binom{4}{1}\binom{3}{1}\binom{5}{2}\binom{3}{2} = 1800$$ such passcodes.

One odd digit is used twice and three even digits are each used once: There are five ways to select the odd digit that is used twice and $\binom{4}{3}$ ways to select three even digits that are each used once. There are $\binom{5}{2}$ ways to select the positions of the odd digit that is used twice and $3!$ ways to arrange the even digits in the remaining three positions. Hence, there are $$\binom{5}{1}\binom{4}{3}\binom{5}{2}3! = 1200$$ such passcodes.

Two odd digits are each used once and one even digit is used three times: There are $\binom{5}{2}$ ways to select the two odd digits that are each used once and four ways to select the even digit that is used thrice. There are $\binom{5}{3}$ ways to select the positions of the even digit that is used thrice and $2!$ ways to arrange the two distinct odd digits in the remaining two positions. Hence, there are $$\binom{5}{2}\binom{4}{1}\binom{5}{3}2! = 800$$ such passcodes.

Two odd digits are each used once, one even digit is used twice, and a different even digit is used once: There are $\binom{5}{2}$ ways to select the two odd digits that are each used once, four ways to select the even digit that is used twice, and three ways to select the even digit that is used once. There are $\binom{5}{2}$ ways to select the positions of the even digit that is used twice. The remaining three distinct numbers can be arranged in the remaining three positions in $3!$ ways. Hence, there are $$\binom{5}{2}\binom{4}{1}\binom{3}{1}\binom{5}{2}3! = 7200$$ such passcodes.

Two odd digits are each used once and three even digits are each used once: There are $\binom{5}{2}$ ways to select the two odd digits that are each used once and $\binom{4}{3}$ ways to select the three even digits that are each used once. The five distinct digits can be arranged in $5!$ orders. Hence, there are $$\binom{5}{2}\binom{4}{3}5! = 4800$$ such passcodes.

Since the six cases are mutually exclusive and exhaustive, there are $$200 + 1800 + 1200 + 800 + 7200 + 4800 = 16000$$ possible passcodes, which agrees with the answer obtained above.