%I #17 Nov 28 2022 12:20:00
%S 3,0,1,0,2,0,1,0,3,0,1,0,2,0,1,2,0,2,1,0,1,2,0,1,0,2,0,1,2,0,2,1,0,1,
%T 3,0,1,0,2,0,1,0,3,0,1,0,2,0,1,2,0,2,1,0,1,2,0,1,0,2,0,1,2,0,2,1,0,2,
%U 0,1,0,2,1,0,1,2,0,1,0,2,0,1,2,0,2,1,0
%N The lexicographically earliest infinite squarefree sequence of nonnegative integers that starts with 3.
%C For any integer k>2, prepending a k at the beginning of this sequence gives the corresponding least word beginning k,3.
%C After the first 14070 letters, this becomes the image of the sequence A356676 under the ruler morphism, n->0(n+1).
%C From _Jianing Song_, Nov 28 2022: (Start)
%C The lexicographically earliest infinite squarefree word starting with 2,3 is not obtained by prepending 2 to the sequence: denote the corresponding sequence by {b(n)}. We have b(n) = a(n-1) for 2 <= n <= 521, but then we have a(1..260) = a(262..521) and a(261) = 2, which means that b(522) > a(521) (otherwise b(1..261) = b(262..522)). Actually, a(521) = 0 and b(522) = 1.
%C a(3768) is the first term equal to 4, and a(4768) is the first term equal to 5. (End)
%H Jianing Song, <a href="/A356679/b356679.txt">Table of n, a(n) for n = 1..10000</a>
%H Siddharth Berera, Andrés Gómez-Colunga, Joey Lakerdas-Gayle, John López, Mauditra Matin, Daniel Roebuck, Eric Rowland, Noam Scully, and Juliet Whidden, <a href="https://arxiv.org/abs/2210.00508">The lexicographically least square-free word with a given prefix</a>, arXiv:2210.00508 [math.CO], 2022.
%o (Python)
%o # check if appending letter to the end of word introduces a square
%o def makes_square(word, letter):
%o new_word = word+[letter]
%o for l in range(1, len(new_word) // 2 + 1):
%o if new_word[-l:] == new_word[-2*l:-l]:
%o return True
%o return False
%o # returns a list of the first n letters of L(word)
%o def build_square_free(word, n):
%o new_word = word[:]
%o for i in range(n-len(word)):
%o next_letter = 0
%o while makes_square(new_word, next_letter):
%o next_letter += 1
%o new_word += [next_letter]
%o return new_word
%o # returns a list of the first n terms of A356679
%o def A356679_list(n):
%o return build_square_free([3], n)
%o (PARI) issquareword(v) = my(n=#v); for(i=1, n\2, if(v[n-2*i+1..n-i] == v[n-i+1..n], return(1))); return(0)
%o the_first_N_terms(N) = my(v=vector(N)); v[1]=3; for(n=2, N, for(k=0, oo, v[n]=k; if(!issquareword(v[1..n]), break()))); v \\ _Jianing Song_, Nov 28 2022
%Y Cf. A356676.
%Y Other word starts: A007814 (w=0), A356677 (w=1), A356678 (w=2), this sequence (w=3), A356680 (w=1,2), A356681 (w=1,3), A356682 (w=2,1).
%K nonn
%O 1,1
%A _Joey Lakerdas-Gayle_, Oct 18 2022
%E Name edited by _N. J. A. Sloane_, Nov 26 2022