%I #8 Jan 24 2025 11:58:59
%S 1,2,3,4,5,6,7,8,9,10,1,11,12,2,13,3,14,4,15,5,16,6,17,7,18,8,19,9,20,
%T 21,22,12,21,22,23,24,25,26,27,28,29,30,31,32,13,33,34,35,36,37,38,39,
%U 40,41,42,14,43,44,34,43,44,45,46,47,48,49,50,51,52,15
%N Lexicographically earliest sequence of positive integers such that any value in the sequence, say v, appears at most twice, and in case v appears twice, then the decimal expansion of v appears in the concatenation of the values surrounded by the two occurrences of v.
%C Every positive integer appears twice in the present sequence:
%C - we can always extend the sequence with a value not yet in the sequence,
%C - for any n > 1, a(n) is at most one plus the greatest value so far,
%C - every integer appears at least once in the sequence (for any v > 0, v necessarily appears at least once among the 2*v-1 initial terms),
%C - for any v > 0, the first occurrence of v appears before the first occurrence of v+1,
%C - every integer appears twice in the sequence: for any v > 0, the value 10*v appears after the first occurrence of v, so eventually v must appear a second time.
%H Rémy Sigrist, <a href="/A380298/b380298.txt">Table of n, a(n) for n = 1..10000</a>
%H Rémy Sigrist, <a href="/A380298/a380298.pl.txt">Perl program</a>
%o (Perl) # See Links section.
%o (Python)
%o from itertools import count, islice
%o def agen(): # generator of terms
%o adict, an, m, s, sn = dict(), 1, 1, "", [None]
%o for n in count(1):
%o yield an
%o s += str(an)
%o sn.append(len(s))
%o adict[an] = [n] if an not in adict else adict[an] + [n]
%o an = next(k for k in count(m) if k not in adict or (len(adict[k])==1 and str(k) in s[sn[adict[k][0]]:]))
%o while m in adict and len(adict[m]) > 1: m += 1
%o print(list(islice(agen(), 70))) # _Michael S. Branicky_, Jan 19 2025
%Y See A380300 for a similar sequence.
%K nonn,base
%O 1,2
%A _Rémy Sigrist_, Jan 19 2025