This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A335973 #17 May 29 2025 20:43:18 %S A335973 13,24,35,46,57,68,791,202,14,25,36,47,58,691,203,15,26,37,48,591,204, %T A335973 16,27,38,491,205,17,28,391,206,18,291,207,181,208,191,302,131,2002, %U A335973 135,461,303,141,304,151,305,161,306,171,307,182,31,2003,142,308,192,41,2004,152,313,241,2005,162,51,402 %N A335973 The Locomotive Pushing or Pulling its Wagons sequence (see comments for definition). %C A335973 a(1) is the locomotive; a(2), a(3), a(4),... a(n),... are the wagons. To hook a wagon both to its predecessor (on the left) and successor (on the right) you must be able to insert the leftmost digit of a(n) between the last two digits of a(n-1) AND to insert the rightmost digit of a(n) between the first two digits of a(n+1). In mathematical terms, the value of the leftmost digit of a(n) must be between (not equal to) the last two digits of a(n-1) AND the value of the rightmost digit of a(n) must be between (not equal to) the first and the second digit of a(n+1). This is the lexicographically earliest sequence of distinct positive terms with this property. %C A335973 a(n) cannot end in 0 or 9. - _Michael S. Branicky_, Dec 14 2020 %H A335973 Carole Dubois, <a href="/A335973/b335973.txt">Table of n, a(n) for n = 1..5006</a> %e A335973 The sequence starts with 13, 24, 35, 46, 57, 68, 791, 202, 14,... %e A335973 a(1) = 13 as there is no earliest possible locomotive; %e A335973 a(2) = 24 starts with 2 and 4: now 2 < 3 < 4 [3 being the rightmost digit of a(1)] AND 3 < 4 < 5 [4 being the rightmost digit of a(2), 3 and 5 being the first two digits of a(3)]; %e A335973 a(3) = 35 starts with 3 and 5: now 3 < 4 < 5 [4 being the rightmost digit of a(2)] AND 4 < 5 < 6 [5 being the rightmost digit of a(3), 4 and 6 being the first two digits of a(4)]; %e A335973 a(4) = 46 starts with 4 and 6: now 4 < 5 < 6 [5 being the rightmost digit of a(3)] AND 5 < 6 < 7 [6 being the rightmost digit of a(4), 5 and 7 being the first two digits of a(5)]; %e A335973 a(5) = 57 starts with 5 and 7: now 5 < 6 < 7 [6 being the rightmost digit of a(4)] AND 6 < 7 < 8 [7 being the rightmost digit of a(5), 6 and 8 being the first two digits of a(6)]; %e A335973 a(6) = 68 starts with 6 and 8: now 6 < 7 < 8 [7 being the rightmost digit of a(5)] AND 7 < 8 < 9 [8 being the rightmost digit of a(6), 7 and 9 being the first two digits of a(7)]; %e A335973 a(7) = 791 starts with 7 and 9: now 7 < 8 < 9 [8 being the rightmost digit of a(6)] AND 2 > 1 > 0 [1 being the rightmost digit of a(7); 2 and 0 being the first two digits of a(8)]; etc. %o A335973 (Python) %o A335973 def between(i, j, k): %o A335973 return i < j < k or i > j > k %o A335973 def dead_end(k): %o A335973 rest, last = divmod(k, 10) %o A335973 if last in {0, 9}: return True %o A335973 return abs(rest%10 - last) <= 1 %o A335973 def aupto(n, seed=13): %o A335973 train, used = [seed], {seed} %o A335973 for n in range(2, n+1): %o A335973 caboose = train[-1] %o A335973 cabbody, cabhook = divmod(caboose, 10) %o A335973 h1, h2 = sorted([cabbody%10, cabhook]) %o A335973 hooks = set(range(h1+1, h2)) %o A335973 pow10 = 10 %o A335973 an = min(hooks)*pow10 %o A335973 while an in used or dead_end(an): an += 1 %o A335973 hook = an//pow10 %o A335973 while True: %o A335973 if hook in hooks: %o A335973 if between(hook, cabhook, an//(pow10//10)%10): %o A335973 train.append(an) %o A335973 used.add(an) %o A335973 break %o A335973 else: pow10 *= 10 %o A335973 an = max(an+1, min(hooks)*pow10) %o A335973 while an in used or dead_end(an): an += 1 %o A335973 hook = an//pow10 %o A335973 return train # use train[n-1] for a(n) %o A335973 print(aupto(65)) # _Michael S. Branicky_, Dec 14 2020 %Y A335973 Cf. A335971 (locomotive pulling to the left) and A335972 (locomotive pushing to the right). %K A335973 base,nonn %O A335973 1,1 %A A335973 _Eric Angelini_ and _Carole Dubois_, Jul 03 2020