cp's OEIS Frontend

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.

A335972 The Locomotive Pushing the Wagons to the Right sequence (see Comments lines for definition).

This page as a plain text file.
%I A335972 #16 Dec 14 2020 01:36:07
%S A335972 2,13,14,15,16,17,18,91,201,202,31,203,24,25,26,27,28,92,41,204,35,36,
%T A335972 37,38,93,42,51,205,46,47,48,94,52,61,206,57,58,95,62,71,207,68,96,72,
%U A335972 81,208,97,82,131,301,302,132,133,141,303,142,134,53,143,144,63,145,64,73,146,74
%N A335972 The Locomotive Pushing the Wagons to the Right sequence (see Comments lines for definition).
%C A335972 a(1) is the (pushing) locomotive; a(2), a(3), a(4),... a(n),... are the wagons. To hook a wagon to its successor (on the right) you must be able to insert the rightmost digit of a(n) between the first two digits of a(n+1). In mathematical terms, 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 A335972 a(n) cannot end in 0 or 9. - _Michael S. Branicky_, Dec 14 2020
%H A335972 Carole Dubois, <a href="/A335972/b335972.txt">Table of n, a(n) for n = 1..5001</a>
%e A335972 The sequence starts with 2, 13, 14, 15, 16, 17, 18, 91, 201, 202,...
%e A335972 a(1) = 2 as there is no earliest possible (pushing to the right) locomotive;
%e A335972 a(2) = 13 starts with 1 and 3: now 1 < 2 < 3 [2 being the rightmost digit of a(1)];
%e A335972 a(3) = 14 starts with 1 and 4: now 1 < 3 < 4 [3 being the rightmost digit of a(2)];
%e A335972 a(4) = 15 starts with 1 and 5: now 1 < 4 < 5 [4 being the rightmost digit of a(3)];
%e A335972 (...)
%e A335972 a(8) = 91 starts with 9 and 1: now 9 > 8 > 1 [8 being the rightmost digit of a(7)];
%e A335972 a(9) = 201 starts with 2 and 0: now 2 > 1 > 0 [1 being the rightmost digit of a(8)];
%e A335972 a(10) = 202 starts with 2 and 0: now 2 > 1 > 0 [1 being the rightmost digit of a(9)]; etc.
%o A335972 (Python)
%o A335972 def dead_end(k): return k%10 in {0, 9}
%o A335972 def aupto(n, seed=2):
%o A335972   train, used = [seed], {seed}
%o A335972   for n in range(2, n+1):
%o A335972     caboose = train[-1]
%o A335972     hook = caboose % 10
%o A335972     low2, high2 = 10 + (hook + 1), 90 + (hook - 1)
%o A335972     an, pow10b = low2, 1
%o A335972     while an in used or dead_end(an): an += 1
%o A335972     first2 = an//pow10b
%o A335972     a2, b2 = divmod(first2, 10)
%o A335972     while True:
%o A335972       if a2 < hook < b2 or a2 > hook > b2:
%o A335972         train.append(an)
%o A335972         used.add(an)
%o A335972         break
%o A335972       if first2 > high2:
%o A335972         pow10b *= 10
%o A335972         an = low2*pow10b
%o A335972       else:
%o A335972         an += pow10b
%o A335972         an -= an%pow10b
%o A335972       while an in used or dead_end(an): an += 1
%o A335972       first2 = an//pow10b
%o A335972       a2, b2 = divmod(first2, 10)
%o A335972   return train    # use train[n-1] for a(n)
%o A335972 print(aupto(66))  # _Michael S. Branicky_, Dec 14 2020
%Y A335972 Cf. A335971 (locomotive pulling to the left) and A335973 (two locomotives).
%K A335972 base,nonn
%O A335972 1,1
%A A335972 _Eric Angelini_ and _Carole Dubois_, Jul 03 2020