Defining terms of Gijswijt's sequence I was looking up this sequence on wikipedia Gijswijit sequnce.I then wanted to define the $n^{th}$ term of the sequence. I figured it out as follows:
$T_n=b_nb_ns_n$ where $b_{n+1}=b_nb_ns_n$. But I cannot figure out how to define $s_n$.
 A: $S_n$ isn't really 'defined', it is a fix from the sequence.
From OEIS, the sequence continues:
$$1, 1, \mathbf{2}, 1, 1, 2, \mathbf{2, 2, 3}, 1, 1, 2, 1, 1, 2, 2, 2, 3, \mathbf{2}, 1, 1, 2, 1, 1, 2, 2, 2,\\ 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2,\mathbf{2, 2, 3, 2, 2, 2, 3, 3, 2}, 1, 1, 2$$
So we 'define':


*

*$S_1=2$

*$S_2=2,2,3$

*$S_3=2$

*$S_4=2,2,3,2,2,3,3,2$


as the next terms of the pre-calculated sequence, after the repetition, until we reach a $1$.
A: The definition of the $S_n$ strings at the Wikpedia page may be confusing, since it tries to explain it in an intuitive way instead of giving a rigorous definition. I will try to give a more rigorous definition below. Keep in mind that the $B_n$ are all prefixes of Gijswijt's sequence.
The $B_n$ and $S_n$ strings can be recursively defined as follows. Firstly, $B_1:=1$. After we have defined $B_n$ for some $n$, it turns out that $B_nB_n$ is also a prefix of Gijswijt's sequence. Furthermore, there must occur a 1 at some point in Gijswijt's sequence after $B_nB_n$. Therefore, we can define $S_n$ as the smallest string such that $B_nB_nS_n1$ is a prefix of Gijswijt's sequence. Now define $B_{n+1}:=B_nB_nS_n$.
The claims made in my definition are proved in this article. There, the strings $B_n$ and $S_n$ have an extra superscript $(1)$, so they are denoted by $B_n^{(1)}$ and $S_n^{(1)}$.
There is an alternative way to construct the strings $S_1,S_2,\dots$. For this, see the first three lines of the proof of Theorem 3.5 in the same article. I explain this construction below.
Let $\mathcal{C}(S)$ denote the curling number of a string $S$. Let $\mathcal{C}^{(2)}(S):=\max(\mathcal{C}(S),2)$. Next, define the sequence $A^{(2)}=a^{(2)}(1),a^{(2)}(2),\dots$ in the following way: $a^{(2)}(1):=2$, and $$a^{(2)}(n+1):=\mathcal{C}^{(2)}(a^{(2)}(1),\dots,a^{(2)}(n))$$ for all $n\geq1$. Now, let $I=\{i_1,i_2,\dots\}$ be the set of integers $i\geq1$ such that $\mathcal{C}(a^{(2)}(1),\dots,a^{(2)}(i))=1$. Then for all $n\geq1$, the string $S_{n+1}$ equals the string $(a^{(2)}(i_n+1),a^{(2)}(i_n+2),\dots,a^{(2)}(i_{n+1}))$. This gives us the strings $S_2,S_3,\dots$ The missing string $S_1$ is the string $2$.
The following Python algorithm uses this alternative construction to compute the first 100 S strings. Note that this is much faster than  just computing the terms of Gijswijt's sequence until you have encountered the first 100 S strings.
def Cn(X): 
    l=len(X)
    cn=1
    for i in range(1,int(l/2)+1):
        j=i
        while(X[l-j-1]==X[l-j-1+i]):
            j=j+1
            if j>=l:
                break
        candidate=int(j/i)
        if candidate>cn:
            cn=candidate
    return cn

A2=[2]
S=[2]
i=0
while(True):
    c=Cn(A2)
    if c==1:
        print(S)
        i=i+1
        if i==100:
            break
        S=[]
    A2.append(max(c,2))
    S.append(max(c,2))

