TITLE: Explicit form for a difficult sequence
QUESTION [6 upvotes]: Let us define infinite sequence $x_n$ as such: the first term of the sequence is $x_1=1$. Then, the next $x_1$ terms are 2. The next term is 1. The next $x_2$ terms are 2. The next term is 1. The next $x_3$ terms are 2. The next term is 1. And so and so forth...
Can anyone provide explicit formula for the $n$th term of this sequence? Or please provide any insight on any patterns that may exist.
For reference, here is how the sequence goes for the first several terms:
1 2 1 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 2 1

REPLY [9 votes]: This is $A001468$ in the OEIS.
The formula is:
$$a_n = \lfloor(n+1)\varphi\rfloor - \lfloor n\varphi\rfloor,$$
where $\varphi = \frac{1+\sqrt5}2$ is the golden ratio.