<s>[INST] Generating function with tough restrictions 
In how many ways can a coin be flipped $25$ times in a row so that exactly $5$ heads occur and no more than $7$ tails occur consecutively?

For the heads, I think that it is $\binom{25}{5}$, but I do not know what to do with the tails restriction. 
Not sure how to approach this problem. It is from the advanced section in the generating functions chapter in my book.
 [/INST] More generally, we might ask how many sequences of flips of length $n$ have $m$ heads and no more than seven tails in a row.  We will find a bivariate generating function for this problem.
First suppose we drop the constraint that the sequence must contain exactly $m$ heads, retaining the requirement that there be no more than seven tails in a row; let's say such a sequence is "acceptable".  Let $f(z)$ be the generating function for the number of acceptable sequences of length $n$. An acceptable sequence consists of a sequence of zero to seven tails, or a sequence of zero to seven tails followed by a head, followed by an acceptable sequence. In terms of the generating function,this translates to
$$f(z) = (1+z+z^2+ \dots +z^7)  (1 + z f(z))$$
We can insert a "marker" for the head in this equation and convert the generating function into a bivariate generating function where the number of acceptable strings of length $n$ with $m$ heads is the coefficient of $u^m z^n$:
$$f(u,z) = (1+z+z^2+ \dots +z^7)  (1 + uz f(u,z))$$
Noting that $1+z+z^2+ \dots +z^7 = (1-z^8)/(1-z)$, we can solve the preceding equation for $f(u,z)$:
$$f(u,z) = \frac{(1-z^8)/(1-z)}{1-uz(1-z^8)/(1-z)}$$
In a sense this bivariate generating function is the general solution, but let's see if we can find the answer to the original problem, which is the coefficient of $u^5 z^{25}$ in $f(u,z)$.  We start by expanding $f(u,z)$ as a series in $u$.
$$f(u,z) = \frac{1-z^8}{1-z} \sum_{i=0}^{\infty} z^i \left(  \frac{1-z^8}{1-z} \right)^i u^i$$
The coefficient of $u^5$ is
$$\begin{align}
[u^5] f(u,z) &= \frac{1-z^8}{1-z}  z^5 \left(  \frac{1-z^8}{1-z} \right)^5  \\
&= z^5 (1-z^8)^6 (1-z)^{-6} \\
&= z^5 (1 - 6z^8 + 15 z^{16} - O(z^{24})) \sum_{i=0}^{\infty} \binom{6+i-1}{i} z^i
\end{align}$$
From this last equation we see that the coefficient of $u^5 z^{25}$ is
$$[z^{25}][u^5]f(u,z) = \binom{6+20-1}{20} -6 \binom{6+12-1}{12} + 15 \binom{6+4-1}{4} = \boxed{17,892}$$
</s>