How to derive $\cos\frac{n\pi}{3}=\frac{1+3(-1)^{[\frac{n+1}{3}]}}{4}$ Consider the following formula to calculate a trigonometric function:  
$$\cos\frac{n\pi}{3}=\frac{1+3(-1)^{[\frac{n+1}{3}]}}{4}$$ $[x]$ denotes the integer part of $x$. The formula is valid for $n=0,2,4,6,...$    
I'm curious how this formula is derived? Is there any analytical method or is it a pure guessing?

First, observe that
$$\cos\frac{(n+6)\pi}{3}=\cos\left(\frac{n\pi}{3}+2\pi\right)=\cos\frac{n\pi}{3}$$
and
$$(-1)^{\lfloor\frac{(n+6)+1}{3}\rfloor}=(-1)^{\lfloor\frac{n+1}{3}\rfloor+2}=(-1)^{\lfloor\frac{n+1}{3}\rfloor}$$
Hence we only need to consider $n=0$, $n=2$, and $n=4$. These cases are trivial to check to be true; I will do it for $n=2$:
$$\cos\frac{2\pi}{3}=-\frac{1}{2}=\frac{1+3(-1)^{\lfloor\frac{2+1}{3}\rfloor}}{4}$$
Edit:
I misunderstood the question. To derive this formula, we just have to find an expression $E(n)$ such that $E(0)=1$, $E(2)=E(4)=-\frac{1}{2}$, and $E(n+6)=E(n)$. The key here is $(-1)^{\lfloor\frac{n+1}{3}\rfloor}$, which is $6$-periodic and alternates between $1$, $-1$, and $-1$. Going further, the formula
$$\frac{1+3(-1)^{\lfloor\frac{2n+1}{3}\rfloor}}{4}+((-1)^{\lfloor\frac{3n+1}{3}\rfloor}-1)\frac{(-1)^{\lfloor\frac{2n+2}{3}\rfloor}}{2}$$
is valid for $n=0,1,2,3,\dots$
