Question: How many sequences of five elements with repetition allowed can be created from elements of the set $\{1,2,3,4,5,6\}$ in which the last digit is equal to any of the previous digits?
My Answer: Let's use the inclusion-exclusion principle. First we need to know the number of all sequences, that is: $6^5$ since we're allowing repetition. Then let's define the sets for $k\in\{1,2,3,4,5,6\}$: $$ C_k = \{ \text{sequences with last digit equal k and previous digits different than k}\} $$ Clearly the sets $C_k$ are disjoint, since there is no sequence equal to another one with the last digits being different. Therefore, the answer is: $$ 6^5 - |C_1\cup C_2 \cup C_3 \cup C_4 \cup C_5 \cup C_6| = 6^5 - 6\cdot 5^4 $$
Is my answer correct? Any help is highly appreciated! Thanks!
Yes this looks correct. Another method is to directly count the sequences where the last digit is equal to any other:
$6 - - - 6 \to 6^3$
$-\ 6 - -\ 6 \to 5\cdot 6^2$
$- - 6 - 6 \to 5^2\cdot 6$
$- - -\ 6\ 6 \to 5^3$
There are $6$ of the above sequences, one for each number in the set.
$6(6^3 + 5\cdot 6^2 + 5^2\cdot 6 + 5^3) = 4026$