This is an exercise from a book on combinatorics and I can't seem to wrap my head around it: How many numbers are there, made out of 5 distinct digits, which contain '4' and are even. The answer according to the book is 7686.
I distinguished some cases (not sure if I distinguished in a 'smart' way)
- the last digit is 4. In that case, there are 8 possibilities for the first digit (not 0, not 4). The second digit has 8 possibilities (not the first, not 4), the third has 7, the fourth has 6. The total amount is $8\cdot 8\cdot 7\cdot 6 = 2688$.
- the last digit isn't 4. Therefore, the last digit must be 0,2,6 or 8. We must pick 3 digits from the remaining 8 digits. This can be done in $8 \cdot 7 = 56$ ways. These 3 digits along with '4' have to be distributed over the first 4 places, giving a total of $56 \cdot 4 \cdot 4! = 5376$ ways. However, these include some invalid numbers: those starting with $0$. These have to be substracted. The first digit is fixed, the last digit can be $2,6,8$, so 3 possibilities. We have to pick 2 digits from the remaining 7 digits. This can be done in $7 \cdot 6/2 = 21$ ways. We then need to distribute these two digits and '4' over 3 spaces, so $3!$ possibilities, giving a total of $3 \cdot 21 \cdot 3! = 378$ invalid numbers.
The total therefore equals $2688 + 5376 - 378 = 7686$ ways.
This seems like a brute force solution. Anyone who can 'smoothen' this, for example by making a smarter choice of distinguished cases?