1

Is there a nice simple formula for the following map:

$$\{1,2,3,4,5,6,\dots\} \mapsto \{1,2,1,2,1,2,\dots \}$$

2 Answers2

0

writing it as some regulations is easy but the formula wasn't that simple: $$1+([-(n/2-[n/2)])$$ note: by [] I mean floor()

infinite
  • 176
0

Your sequence satisfies $$a_n= \begin{cases} 1 &\text{if $n=1$},\\ 2 &\text{if $n=2$},\\ a_{n-2} &\text{if $n\ge 3$}. \end{cases}$$ The characteristic equation is $r^2-1=0$, yielding roots $r = \pm 1$. So $a_n = A(1)^n+B(-1)^n$, and the initial conditions imply that \begin{align} 1 &= A - B \\ 2 &= A + B \\ \end{align} Solving yields $A=3/2$ and $B=1/2$ and hence $a_n=(3+(-1)^n)/2$.

RobPratt
  • 45,619