# Worker's security code - combinatorics

In a certain factory, each worker is given a security code, which must meet two criteria.
(1) It contains at least one even and at least one odd digit
(2) It contains at least three different digits

My attempt:
1. Let's first find the total number of combinations with five digits: $10^5$ (zero is valid at the beginning of the code)
2. Let's find the number of combinations which do not meet the first criterion: $5^5 + 5^5 = 2*5^5$
3. Now, let's find the number or combinations which do not meet the second criterion: It contains one number that is even and one that is odd $10\cdot5$ and excludes the numbers that have only odd and even digits ($2^5-2)$ So, the number we are looking for is: $(2^5-2)(10)(5)$
4. We sum everything up and get the answer: $10^5-2*5^5-50*(2^5-2)$

Could you please review my attempt to solve this problem?

• So, their security code must be exactly $5$ digits long? – user12345 Apr 18 '17 at 20:32
• Yes, that's the exact length. – ILoveChess Apr 18 '17 at 20:32
• Your idea is almost right, but you need to consider that maybe you took out too many cases. Could there possibly be some numbers that fail to meet both criteria? If so, you've subtracted those numbers off twice when you needn't have. Search for the Inclusion-Exclusion Principle. – user12345 Apr 18 '17 at 20:34
• @String, first - I choose the first digit in 10 ways. Let's say it's even, then I choose the odd digit in 5 ways. Now, I only need to arrange the digits to form a code. Each "space" in the code can be occupied by two numbers ($2^5$), but the codes MUST have at least two different numbers (I have already subtracted those composed of only one number in item 2), thus I sutract 2 from the number in parentheses. – ILoveChess Apr 18 '17 at 21:03
• Ah, no! I found an error, namely that the figure in item 3 should be $(2^5-2)\cdot 5^2$, since $5^2$ is the number of ways to choose one even and one odd digit to work with. – String Apr 18 '17 at 21:32

Steps 1 and 2 are correct: first calculate the number of possible combinations, then subtract all combinations which consist only of uneven or odd digits. In step 3 however, you made an error. Since there must be at least three different digits, we can subtract all codes which consist of only one or two digits. The former case was already discarded, since we are sure that the remaining codes consist of at least two different digits (an even and an odd one). We must thus subtract all combinations which consist of exactly one even and one odd digit. There are $5 \cdot 5$ ways to select these digits, and $2^5 - 2$ ways in which they can appear. As such, the total number of possible combinations equals $10^5 - 2 \cdot 5^5 - 30 \cdot 5^2 = 93,000$.