login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Lexicographically earliest sequence such that each subsequence enclosed by two equal terms is distinct.
8

%I #20 Dec 07 2024 02:03:04

%S 1,1,2,1,2,2,1,3,1,2,3,1,2,4,1,2,3,2,1,3,2,1,4,1,2,3,3,1,2,4,2,1,3,4,

%T 1,2,3,4,1,2,4,3,1,2,4,3,2,1,4,2,1,3,5,1,2,3,4,2,1,3,5,2,1,3,4,2,1,4,

%U 3,1,2,5,1,2,3,4,3,1,2,5,2,1,3,4,4,1,2,3,5,1,2,4,3,4,1,2,5,3,1,2,4,5,1,2,3,4,5,1,2,3,5

%N Lexicographically earliest sequence such that each subsequence enclosed by two equal terms is distinct.

%C A new value is always followed by 1.

%H Samuel Harkness, <a href="/A366493/b366493.txt">Table of n, a(n) for n = 1..10000</a>

%H Samuel Harkness, <a href="/A366493/a366493.m.txt">MATLAB program</a>

%e a(2)=1 because the subsequence (1,1) has not occurred before.

%e a(8)=3 because every smaller number would form a subsequence that has occurred already. a(8) cannot be 1 because this would make the subsequence (1,1), which was seen before at i=1,2. a(8) cannot be 2 because then we would have the subsequence (2,1,2) for a second time (first at i=3-5): 1,1,2,1,2,2,1,2

%o (MATLAB) See Links section.

%o (Python)

%o from itertools import islice

%o def agen(): # generator of terms

%o m, a = set(), []

%o while True:

%o an, allnew = 0, False

%o while not allnew:

%o allnew, an, mn = True, an+1, set()

%o for i in range(len(a)):

%o if an == a[i]:

%o t = tuple(a[i:]+[an])

%o if t in m or t in mn: allnew = False; break

%o mn.add(t)

%o yield an; a.append(an); m |= mn

%o print(list(islice(agen(), 111))) # _Michael S. Branicky_, Dec 06 2024

%Y Cf. A330896.

%K nonn,easy

%O 1,3

%A _Neal Gersh Tolunsky_, Oct 10 2023