OFFSET
0,3
LINKS
Michael De Vlieger, Table of n, a(n) for n = 0..10000
EXAMPLE
a(10) = 80 as the last digit of a(9) = 9 is 9, thus the first digit of a(10) must be 8. As 8 has already been used the next smallest number starting with 8 is 80.
a(16) = 21 as the last digit of a(15) = 13 is 3, thus the first digit of a(16) must be 2 or 4. As 2, 4 and 20 have already been used the next smallest number starting with 2 is 21.
MATHEMATICA
Block[{a = {0}, k}, Do[k = 1; While[Nand[FreeQ[a, k], Abs[First@ IntegerDigits[k] - Mod[a[[-1]], 10]] == 1], k++]; AppendTo[a, k], {i, 76}]; a] (* Michael De Vlieger, Feb 23 2021 *)
PROG
(Python)
def nextd(strn, d):
n = int(strn) if strn != "" else 0
return n+1 if str(n+1)[0] == str(d) else int(str(d)+'0'*len(strn))
def aupton(term):
alst, aset = [0], {0}
lastdstr = ["" for d in range(10)]
for n in range(1, term+1):
lastdig = alst[-1]%10
firstdigs = set([max(lastdig-1, 0), min(lastdig+1, 9)]) - {0}
cands = [nextd(lastdstr[d], d) for d in firstdigs]
m = min(cands)
argmin = cands.index(m)
alst.append(m)
strm = str(m)
lastdstr[int(strm[0])] = strm
return alst
print(aupton(76)) # Michael S. Branicky, Feb 23 2021
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Scott R. Shannon, Feb 23 2021
STATUS
approved