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\$ 2
s, 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 -> 1
1 -> 2
2 -> 1
3 -> 1
4 -> 2
5 -> 2
6 -> 2
7 -> 1
8 -> 1
9 -> 2
10 -> 2
11 -> 2
12 -> 2
13 -> 2
14 -> 1
15 -> 1
16 -> 2
17 -> 2
18 -> 2
19 -> 2
20 -> 2
21 -> 2
22 -> 2
23 -> 1
24 -> 1
25 -> 2
26 -> 2
27 -> 2
28 -> 2
29 -> 2
This is code-golf so the shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
indefinitely print the sequence
too literally, but the tag wiki for sequence allows returns an infinite lazy iterator/generator \$\endgroup\$