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 of positive integers such that the n-th pair of identical terms encloses exactly a(n) terms.
3

%I #32 Jul 25 2023 09:14:47

%S 1,2,1,3,2,3,1,2,4,3,4,5,3,6,7,4,3,8,6,9,7,8,4,10,3,7,4,6,8,9,11,10,

%T 12,3,9,13,7,3,11,9,14,15,13,16,17,7,18,3,19,20,11,14,9,20,17,15,19,

%U 20,18,21,11,22,3,23,24,25,26,14,17,9,27,28,29,15,26,19

%N Lexicographically earliest sequence of positive integers such that the n-th pair of identical terms encloses exactly a(n) terms.

%C Pairs are numbered according to the position of the second term.

%H Neal Gersh Tolunsky, <a href="/A363654/b363654.txt">Table of n, a(n) for n = 1..10000</a>

%H Eric Angelini, <a href="http://cinquantesignes.blogspot.com/2023/06/a-seq-with-strange-behavior-or-not.html">A seq with a strange behavior (or not)?</a>

%H Neal Gersh Tolunsky, <a href="/A363654/a363654.png">Scatterplot of first 100000 terms</a>

%e a(1) = 1. The 1st constructed pair encloses 1 term: [1, 2, 1].

%e a(2) = 2. The 2nd constructed pair encloses 2 terms: [2, 1, 3, 2].

%e a(3) = 1. The 3rd constructed pair encloses 1 term: [3, 2, 3].

%e a(4) = 3. The 4th constructed pair encloses 3 terms: [1, 3, 2, 3, 1].

%e a(5) = 2. The 5th constructed pair encloses 2 terms: [2, 3, 1, 2].

%e a(6) = 3. The 6th constructed pair encloses 3 terms: [3, 1, 2, 4, 3].

%e a(7) = 1. The 7th constructed pair encloses 1 term: [4, 3, 4].

%e ...

%o (Python)

%o from itertools import count, islice

%o def agen(): # generator of terms

%o a, indexes = [1], {1: 0}

%o yield a[-1]

%o for i in count(0):

%o num = 1

%o while True:

%o if num in indexes:

%o if (len(a) - indexes[num]) == (a[i]+1):

%o an = num; indexes[an] = len(a); a.append(an); yield an

%o break

%o else:

%o num += 1

%o else:

%o an = max(a)+1; indexes[an] = len(a); a.append(an); yield an

%o num = 1

%o print(list(islice(agen(), 100))) # _Gavin Lupo_ and _Michael S. Branicky_, Jun 13 2023

%Y Cf. A026272, A363708, A363757.

%K nonn

%O 1,2

%A _Eric Angelini_ and _Gavin Lupo_, Jun 13 2023