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.

A335971 The Locomotive Pulling the Wagons to the Left sequence (see Comments lines for definition).

This page as a plain text file.
%I A335971 #19 Dec 14 2020 01:35:57
%S A335971 13,20,14,24,30,15,25,31,26,35,40,16,27,36,41,28,37,42,38,46,50,17,29,
%T A335971 39,47,51,48,52,49,53,402,18,57,60,19,58,61,59,62,302,102,103,104,105,
%U A335971 106,107,63,403,108,64,502,109,68,70,69,71,202,113,203,114,204,115,205,116,206
%N A335971 The Locomotive Pulling the Wagons to the Left sequence (see Comments lines for definition).
%C A335971 a(1) is the locomotive; a(2), a(3), a(4),... a(n),... are the successive wagons. To hook a wagon to its predecessor (on the left) you must be able to insert the leftmost digit of a(n) between the last 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 penultimate and the last digit of a(n-1). This is the lexicographically earliest sequence of distinct positive terms with this property.
%H A335971 Carole Dubois, <a href="/A335971/b335971.txt">Table of n, a(n) for n = 1..5001</a>
%e A335971 The sequence starts with 13, 20, 14, 24, 30,...
%e A335971 a(1) = 13 as there is no earliest possible (pulling to the left) locomotive;
%e A335971 a(2) = 20 starts with 2 and 1 < 2 < 3 [1 and 3 being the last two digits of a(1)];
%e A335971 a(3) = 14 starts with 1 and 2 > 1 > 0 [2 and 0 being the last two digits of a(2)];
%e A335971 a(4) = 24 starts with 2 and 1 < 2 < 4 [1 and 4 being the last two digits of a(3)]; etc.
%o A335971 (Python)
%o A335971 def dead_end(k): return abs((k//10)%10 - k%10) <= 1
%o A335971 def aupto(n, seed=13):
%o A335971   train, used = [seed], {seed}
%o A335971   for n in range(2, n+1):
%o A335971     caboose = train[-1]
%o A335971     h1, h2 = sorted([(caboose//10)%10, caboose%10])
%o A335971     hooks = set(range(h1+1, h2))
%o A335971     pow10 = 10
%o A335971     an = min(hooks)*pow10
%o A335971     while an in used: an += 1
%o A335971     hook = an//pow10
%o A335971     while True:
%o A335971       if hook in hooks:
%o A335971         if not dead_end(an):
%o A335971           train.append(an)
%o A335971           used.add(an)
%o A335971           break
%o A335971       else: pow10 *= 10
%o A335971       an = max(an+1, min(hooks)*pow10)
%o A335971       while an in used: an += 1
%o A335971       hook = an//pow10
%o A335971   return train    # use train[n-1] for a(n)
%o A335971 print(aupto(65))  # _Michael S. Branicky_, Dec 14 2020
%Y A335971 Cf. A335972 (locomotive pushing to the right) and A335973 (two locomotives).
%K A335971 base,nonn
%O A335971 1,1
%A A335971 _Eric Angelini_ and _Carole Dubois_, Jul 03 2020