How many sequences of numbers $\{a_1...a_5\}$ where $a_i \in \{1...25\}$ satisfy $a_{i+1} \leq a_i + 2$ Here's how it looks:

1 1 1 1 1 
  1 1 1 1 2 
  1 1 1 1 3 
  1 1 1 2 1 
  1 1 1 2 2 
  1 1 1 2 3 
  1 1 1 2 4 
  1 1 1 3 1 
  ......... 
  25 25 25 25 24 
  25 25 25 25 25 

Counting sequences using a simple script gives an answer of 386958
I already know that if I had just $a_{i+1} \leq a_i$, it would be ${25+5-1 \choose 5}=118755$, but I don't know what to do with that extra "+2" in $a_{i+1} \leq a_i + 2$
What is the mathematical solution here? Do I have to use a generating function for this?
 A: This answer is probably much more work than just counting by using a script, but here goes. . . 
We'll use inclusion/exclusion.  The total number of $5$-tuples is $25^5$, and we have to exclude those which lie in the union of the four sets
$$S_k=\{\,{\bf a}\mid a_{k+1}>a_k+2\,\}\ .$$


*

*To count $S_1$ we need to arrange $25$ dots in the following way, where $\bullet$ represents a compulsory dot and $\circ$ represents an optional dot:
$$\qquad\qquad\cdots\circ a_1\bullet\bullet\circ\cdots a_2\circ\cdots
  \qquad\qquad(1)$$
This is just the standard problem of counting the solutions to $x_1+x_2+x_3=25$ with $x_2\ge2$, and the number of possibilities is $C(23,2)$.  We then have to choose arbitrary values for $a_3,a_4,a_5$, so $|S_1|=C(23,2)25^3$.  The same holds for $S_2,S_3,S_4$.

*Arrangements in $S_1\cap S_2$ look like this:
$$\qquad\qquad\cdots\circ a_1\bullet\bullet\circ\cdots a_2\bullet\bullet\circ\cdots a_3
  \circ\cdots\qquad\qquad(2)$$
and we get $|S_1\cap S_2|=C(21,3)25^2$.  There are two more terms like this. . . 

*. . . but $S_1\cap S_3$ is different.  It will look like two independent copies of $(1)$ together with one "free choice", so $|S_1\cap S_3|=C(23,2)^225$.


Continuing in a similar way, the total number is
$$\eqalign{25^5-4C(23,2)25^3
  &{}+(3C(21,3)25^2+3C(23,2)^225)\cr
  &{}-(2C(19,4)25+2C(21,3)C(23,2))+C(17,5)\ ,\cr}$$
and guess what?? . . . if you evaluate it you get $386958$.
A: You have:
\begin{align}
a_1 &\le 25 \\
a_2 &\le a_1 - 2 \\
a_3 &\le a_2 - 2 \\
a_4 &\le a_3 - 2 \\
a_5 &\le a_4 - 2 \\
a_5 &\ge 1
\end{align}
Define new variables:
\begin{align}
x_1 = 25  - a_1 &\ge 0 \\
x_2 = a_1 - a_2 &\ge 2 \\
x_3 = a_2 - a_3 &\ge 2 \\
x_4 = a_3 - a_4 &\ge 2 \\
x_5 = a_4 - a_5 &\ge 2 \\
x_6 = a_5       &\ge 1
\end{align}
To the above add $x_1 + x_2 + x_3 + x_4 + x_5 = 25$. Set this up by generating functions:
$$
[z^{25}] \frac{z}{1 - z} \left( \frac{z^2}{1 - z} \right)^4 \frac{1}{1 - z}
  = [z^{25}] \frac{z^9}{(1 - z)^6}
  = [z^{16}] (1 - z)^{-6}
  = \binom{-6}{16} (-1)^{16}
  = 20349
$$
A: I believe your script is correct. Below is a MAPLE script. 

z := 0; for i to 25 do for j to 25 do for k to 25 do for l to 25 do for m to 25 do if $(i+2\ge j)\text{ and } (j+2 \ge k) \text{ and } (k+2\ge l) \text{ and } (l+2\ge m)$ then z := z+1 end if end do end do end do end do end do;

I end up with the count being $z=386958$. The script is correct, as deleting the $+2$'s, it obtains ${29\choose 5} = 118755$. 
