OFFSET
1,1
COMMENTS
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.
LINKS
Carole Dubois, Table of n, a(n) for n = 1..5001
EXAMPLE
The sequence starts with 13, 20, 14, 24, 30,...
a(1) = 13 as there is no earliest possible (pulling to the left) locomotive;
a(2) = 20 starts with 2 and 1 < 2 < 3 [1 and 3 being the last two digits of a(1)];
a(3) = 14 starts with 1 and 2 > 1 > 0 [2 and 0 being the last two digits of a(2)];
a(4) = 24 starts with 2 and 1 < 2 < 4 [1 and 4 being the last two digits of a(3)]; etc.
PROG
(Python)
def dead_end(k): return abs((k//10)%10 - k%10) <= 1
def aupto(n, seed=13):
train, used = [seed], {seed}
for n in range(2, n+1):
caboose = train[-1]
h1, h2 = sorted([(caboose//10)%10, caboose%10])
hooks = set(range(h1+1, h2))
pow10 = 10
an = min(hooks)*pow10
while an in used: an += 1
hook = an//pow10
while True:
if hook in hooks:
if not dead_end(an):
train.append(an)
used.add(an)
break
else: pow10 *= 10
an = max(an+1, min(hooks)*pow10)
while an in used: an += 1
hook = an//pow10
return train # use train[n-1] for a(n)
print(aupto(65)) # Michael S. Branicky, Dec 14 2020
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Eric Angelini and Carole Dubois, Jul 03 2020
STATUS
approved