How to find a formula for a periodic sequence? I would like to find the formula for a periodic sequence such as 4, 1, 1/4, 1/4, 1, 4... with a period of 6


Here    is      a    variation    which  utilizes  the  special structure    of   the sequence.
The sequence can be written as
  \begin{align*}
(a_n)_{n\geq 0}&=\left(4,1,\frac{1}{4},\frac{1}{4},1,4,4,1,\frac{1}{4},\ldots\right)\\
&=\left(4^1,4^0,4^{-1},4^{-1},4^0,4^1,4^1,4^0,4^{-1},\ldots\right)
\end{align*}

Since 
\begin{align*}
\left(1-\left(n \text{ mod} (3)\right)\right)_{n\geq 0}=(1,0,-1,1,0,-1,1,0,-1,\ldots)
\end{align*}
and
\begin{align*}
\left((-1)^{\left\lfloor\frac{n}{3}\right\rfloor}\right)_{n\geq 0}=(1,1,1,-1,-1,-1,1,1,1,\ldots)
\end{align*}
we obtain
\begin{align*}
\left((-1)^{\left\lfloor\frac{n}{3}\right\rfloor}\left(1-\left(n \text{ mod} (3)\right)\right)\right)_{n\geq 0}
=(1,0,-1,-1,0,1,1,0,-1,\ldots)
\end{align*}

We conclude the sequence $(a_n)_{n\geq 0}$ can be written as
  \begin{align*}
(a_n)_{n\geq 0}=\left(4^{(-1)^{\left\lfloor\frac{n}{3}\right\rfloor}\left(1-\left(n \text{ mod} (3)\right)\right)}\right)_{n\geq 0}
\end{align*}

