Does the sequence $1,-1,1,1,-1,1,1,1,-1,1,1,1,1,-1,1,1,1,1,1,-1,\ldots$ have a closed form? 
Question : Can we represent the following sequence $\{a_n\}\ (n\ge 0)$ as a closed form?$$a_n : 1,-1,1,1,-1,1,1,1,-1,1,1,1,1,-1,1,1,1,1,1,-1,\ldots$$ Suppose that there exist ${(i+1)}$ $1_s$ between the $i_{th}$ $(-1)$ and ${(i+1)}_{th}$ $(-1)$ for $i=1,2,\cdots$.

Though I've thought about this, I'm facing difficulty. Can anyone help? A simpler form is better if closed forms exist.
Motivation : I've known that a periodic sequence can be represented as a closed form. For example, if a sequence $\{b_n\}\ (n\ge0)$ is defined as
$$b_n : 1,1,1,-1,1,1,1,1,1,-1,1,1,1,1,1,-1,\ldots,$$
(Suppose that $b_n=-1\ (n\equiv 4),b_n=1\ (n\not\equiv 4)\ ($mod$ 6$))
then we can represent $\{b_n\}$ as
$$b_n=\frac 13\left(2+(-1)^n+2\cos\frac{n\pi}{3}-2\cos\frac{2n\pi}{3}\right).$$
Then, I got interested in the above sequence $\{a_n\}$. I'm facing difficulty because $\{a_n\}$ is not periodic. 
 A: $$a_n=-(-1)^{\left\lceil\frac{-3+\sqrt{8n+9}}{2}\right\rceil-\left\lfloor\frac{-3+\sqrt{8n+9}}{2}\right\rfloor}.$$
or
$$a_n=-\cos\pi\left( {\left\lceil\frac{-3+\sqrt{8n+9}}{2}\right\rceil-\left\lfloor\frac{-3+\sqrt{8n+9}}{2}\right\rfloor} \right).$$

The basic idea of find this form is find a pattern of place of $-1$ occurs. By simple calculation, we can find that $-1$ occurs when $n=\frac{1}{2}k(k+1)+k$ for some $k$.
Let we find a function $f$ satisfy that $f(\frac{1}{2}(k^2+3k))$ is odd and otherwise $f(n)$ is even. If we can find this function we can define a sequence $a_n=(-1)^{f(n)}$. But we know that
$$
\lceil x\rceil -\lfloor x\rfloor =\begin{cases} 0 & \text{if $x$ is integer }\\ 1 &\text{otherwise}\end{cases}
$$
and $\frac{1}{2}(n^2+3n)=x\Longleftarrow  x= \frac{-3+\sqrt{8x+9}}{2}$. In that case, $x$ is integer iff $x=\frac{1}{2}(k^2+3k)$ for some $k$. So if we define $f(n)=\lceil x\rceil -\lfloor x\rfloor+1$ then we get desired function.
A: To start with, we want a function $f:\mathbb R \rightarrow  \{0,1\}$ that can tell integers from non-integers. For instance:
$$f(x) = \lceil x \rceil - \lfloor x \rfloor$$
which is $0$ or $1$ according as $x$ is an integer or not.
Next, we want a function $g:\mathbb N \rightarrow \mathbb R$ that is an integer only when its argument is in $\{1,4,8,13,19,\ldots\}$ (i.e. when $a_n = -1$). For instance:
$$g(n)=\sqrt{8n+17}$$
Now it's easy: just take $a_n = 2f(g(n)) - 1$.
