Ones and Twos for days Inspiring myself on a recent challenge, we ought to compute a sequence that is very close to A160242.

Task

Your task is to generate the sequence \$ \{s_i\}_{i=0}^\infty \$:

1, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, ...

Which is more easily understandable in this format:

      1 2 1
    1 2 2 2 1
  1 2 2 2 2 2 1
1 2 2 2 2 2 2 2 1 ...


Another way to think of it is, this sequence is the concatenation of blocks \$b_i, 0 \leq i\$ where block \$b_i\$ is a 1, followed by \$2i + 1\$ 2s, followed by another 1.

Input

If your program takes input, the input is a non-negative integer n, telling you how far you should go in computing the sequence.

The sequence can


be 0-indexed, so that \$s_0 = 1, s_1 = 2, s_2 = 1, ... \$
be 1-indexed, so that \$s_1 = 1, s_2 = 2, s_3 = 1, ... \$


Output

Your code may do one of the following:


indefinitely print the sequence
print/return the term n as given by the input
print/return all the terms up to the term n as given by the input


Test cases

(the test cases are 0-indexed)

0 -&gt; 1
1 -&gt; 2
2 -&gt; 1
3 -&gt; 1
4 -&gt; 2
5 -&gt; 2
6 -&gt; 2
7 -&gt; 1
8 -&gt; 1
9 -&gt; 2
10 -&gt; 2
11 -&gt; 2
12 -&gt; 2
13 -&gt; 2
14 -&gt; 1
15 -&gt; 1
16 -&gt; 2
17 -&gt; 2
18 -&gt; 2
19 -&gt; 2
20 -&gt; 2
21 -&gt; 2
22 -&gt; 2
23 -&gt; 1
24 -&gt; 1
25 -&gt; 2
26 -&gt; 2
27 -&gt; 2
28 -&gt; 2
29 -&gt; 2




This is code-golf so the shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
JavaScript (ES7),  25 24  23 bytes
Returns the \$n\$-th term, 1-indexed.

n=&gt;n&gt;(++n**.5|0)**2?2:1

Try it online!
How?
We have \$a(n)=2\$ iff the difference between \$n+1\$ and the previous square is greater than \$1\$:
$$n+1-\left\lfloor \sqrt{n+1}\right\rfloor^2&gt;1$$
which boils down to:
$$n&gt;\left\lfloor \sqrt{n+1}\right\rfloor^2$$