General integer sequence of period 4 I'm am trying to find a general expression for a periodic sequence of integers $(p, q, r, s)$. 
\begin{align*}
n &:  1,  2,  3,  4,  5,  6,  7,  8,  9\ldots\\ 
a(n)&:  p,  q,  r,  s,  p,  q,  r,  s,  p \ldots
\end{align*}
So far, I'm trying to base the expression on a linear combination of a constant, $\sin(\pi n/2)$, and $\cos(\pi n/2)$, but I still need a 4th basis.  Any clues?   Or, is there a better approach?
 A: Your approach is off to a great start, here are some more specific tips that will get the job done.
The sequence $$f(n) = \frac{p - r}{2}\sin\left(\frac{n\pi}{2}\right) + \frac{p+r}{2}$$
takes values $p, \frac{p+r}{2}, r, \frac{p+r}{2}, p$, etc (so matches what we'd like for odd $n$). We can do something similar to create a function that takes the values we like for even $n$ (using cosine is probably easiest, but you have to be careful with shifting, or negatives).
$$g(n) = \frac{s - q}{2}\cos\left(\frac{n\pi}{2}\right) + \frac{q+s}{2}.$$
But even once you've found a suitable $g$, the sum $f(n) + g(n)$ won't work, because there's interference. 
We can get rid of the interference by making $f(n) = 0$ when $n$ is even (when the function doesn't give terms we want), and $f(n) = 1$ when the function already gives us what we want (so when $n$ is odd). This can be accomplished by multiplying it by 
$$\bar{f}(n) = \sin^2\left(\frac{n\pi}{2}\right),$$
where $\bar f(n)$ takes values $1, 0, 1, 0, \ldots$ (i.e., will be zero for even $n$, and $1$ for odd $n$). You can also see the similar 
$$\bar{g}(n) = \cos^2\left(\frac{n\pi}{2}\right)$$
to get rid of the "bad" terms of $g(n)$.
Thus your sequence can be achieved by 
$$\begin{align*}
a(n) 
&= \bar f(n)f(n) + \bar g(n) g(n) \\[7pt]
&= \sin^2\left(\frac{n\pi}{2}\right)\left( \frac{p - r}{2}\sin\left(\frac{n\pi}{2}\right) + \frac{p+r}{2} \right) + \cos^2\left(\frac{n\pi}{2}\right)\left( \frac{s - q}{2}\cos\left(\frac{n\pi}{2}\right) + \frac{q+s}{2} \right)
\end{align*}$$
which will look rather complicated if you use the $g(x)$ and $\bar g(x)$ I have in mind. It's probably also possible to use an approach that doesn't require a $0/1$-multiplier (some kind of superposition of more trigonometric functions, maybe), but I'm not really familiar with how it would work.
Of course, one might argue it's a bit silly to use such a complicated formula when 
$$a(n) = 
\begin{cases}
p, & n \equiv 1 \pmod 4\\
q, & n \equiv 2 \pmod 4\\
r, & n \equiv 3 \pmod 4\\
s, & n \equiv 0 \pmod 4\\
\end{cases}
$$
will do just fine with much less fuss, but to each their own!
A: Let $k$ denote $n\bmod4$, then:
$a_n=\frac{(k^3-5k^2+6k)p}{2}+\frac{(-k^3+4k^2-3k)q}{2}+\frac{(k^3-3k^2+2k)r}{6}+\frac{(-k^3+6k^2-11k+6)s}{6}$

Found using WolframAlpha:


*

*interpolate[(0,1),(1,0),(2,0),(3,0)]

*interpolate[(0,0),(1,1),(2,0),(3,0)]

*interpolate[(0,0),(1,0),(2,1),(3,0)]

*interpolate[(0,0),(1,0),(2,0),(3,1)]
