OFFSET
1,1
COMMENTS
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.
a(n) cannot end in 0 or 9. - Michael S. Branicky, Dec 14 2020
LINKS
Carole Dubois, Table of n, a(n) for n = 1..5001
EXAMPLE
The sequence starts with 2, 13, 14, 15, 16, 17, 18, 91, 201, 202,...
a(1) = 2 as there is no earliest possible (pushing to the right) locomotive;
a(2) = 13 starts with 1 and 3: now 1 < 2 < 3 [2 being the rightmost digit of a(1)];
a(3) = 14 starts with 1 and 4: now 1 < 3 < 4 [3 being the rightmost digit of a(2)];
a(4) = 15 starts with 1 and 5: now 1 < 4 < 5 [4 being the rightmost digit of a(3)];
(...)
a(8) = 91 starts with 9 and 1: now 9 > 8 > 1 [8 being the rightmost digit of a(7)];
a(9) = 201 starts with 2 and 0: now 2 > 1 > 0 [1 being the rightmost digit of a(8)];
a(10) = 202 starts with 2 and 0: now 2 > 1 > 0 [1 being the rightmost digit of a(9)]; etc.
PROG
(Python)
def dead_end(k): return k%10 in {0, 9}
def aupto(n, seed=2):
train, used = [seed], {seed}
for n in range(2, n+1):
caboose = train[-1]
hook = caboose % 10
low2, high2 = 10 + (hook + 1), 90 + (hook - 1)
an, pow10b = low2, 1
while an in used or dead_end(an): an += 1
first2 = an//pow10b
a2, b2 = divmod(first2, 10)
while True:
if a2 < hook < b2 or a2 > hook > b2:
train.append(an)
used.add(an)
break
if first2 > high2:
pow10b *= 10
an = low2*pow10b
else:
an += pow10b
an -= an%pow10b
while an in used or dead_end(an): an += 1
first2 = an//pow10b
a2, b2 = divmod(first2, 10)
return train # use train[n-1] for a(n)
print(aupto(66)) # Michael S. Branicky, Dec 14 2020
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Eric Angelini and Carole Dubois, Jul 03 2020
STATUS
approved