A counting problem involving ternary sequences 
A ternary sequence is a sequence all of whose elements are the  digits 0, 1 or 2. Find the number of ternary sequences of length 8 in which the digits 0 and 1 each occur an even number of times.  

The first case that should be considered is when we have all 2s, in which case there are certainly an even number of 1s and 0s.  For each 'dilution' of 2s thereafter there are two options: two 1s are placed or two 0s are placed.  There are four such dilutions that can take place so we have $4\times 2 + 1 = 9$ possibilities so far.  However, this method makes counting more difficult than it should be.  Is there a more efficient way of continuing the count?

Do as follows: Define $a_n$ as the number of $n$-sequences with an even number of 0 and an even number of 1, $b_n$ for even/odd, $c_n$ for odd/even and $d_n$ for odd/odd. Then $a_0 = 1$, and $b_0 = c_0 = d_0 = 0$. You can set up recurrences for all for them (think how you can get e.g. odd/even by adding a symbol):
$$
\begin{align*}
a_{n + 1} &= a_n + b_n + c_n \\
b_{n + 1} &= a_n + b_n + d_n \\
c_{n + 1} &= a_n + c_n + d_n \\
d_{n + 1} &= b_n + c_n + d_n
\end{align*}
$$
Define generating functions $A(z) = \sum_{n \ge 0} a_n z^n$ and so on, by the properties of generating functions:
$$
\begin{align*}
\frac{A(z) - a_0}{z} &= A(z) + B(z) + C(z) \\
\frac{B(z) - b_0}{z} &= A(z) + B(z) + D(z) \\
\frac{C(z) - c_0}{z} &= A(z) + C(z) + D(z) \\
\frac{D(z) - d_0}{z} &= B(z) + C(z) + D(z)
\end{align*}
$$
The solution of this nice linear system is:
$$
\begin{align*}
A(z) &= \frac{1 - 2 z - z^2}{(1 - z) (1 + z) (1 - 3 z)} \\
B(z) &= \frac{z}{(1 + z) (1 - 3 z)} \\
C(z) &= \frac{z}{(1 + z) (1 - 3 z)} \\
D(z) &= \frac{2 z}{1 - z) (1 + z) (1 - 3 z)}
\end{align*}
$$
We are really only interested in the $a_n$. Expanding $A(z)$ as partial fractions:
$$
A(z) = \frac{1}{4} \cdot \frac{1}{1 - 3 z} 
         + \frac{1}{4} \cdot \frac{1}{1 + z}
         + \frac{1}{2} \cdot \frac{1}{1 - z}
$$
Reading the geometric series:
$$
a_n = \frac{1}{4} \cdot 3^n + \frac{1}{4} \cdot (-1)^n + \frac{1}{2}
$$
