login
a(0) = 0; for n > 0, a(n) is the smallest positive integer not yet in the sequence such that the first digit of a(n) differs by 1 from the last digit of a(n-1).
1

%I #18 Apr 13 2022 01:14:50

%S 0,1,2,3,4,5,6,7,8,9,80,10,11,20,12,13,21,22,14,30,15,40,16,50,17,60,

%T 18,70,19,81,23,24,31,25,41,26,51,27,61,28,71,29,82,32,33,42,34,35,43,

%U 44,36,52,37,62,38,72,39,83,45,46,53,47,63,48,73,49,84,54,55,64,56,57,65,66,58,74,59

%N a(0) = 0; for n > 0, a(n) is the smallest positive integer not yet in the sequence such that the first digit of a(n) differs by 1 from the last digit of a(n-1).

%H Michael De Vlieger, <a href="/A341909/b341909.txt">Table of n, a(n) for n = 0..10000</a>

%e 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.

%e 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.

%t 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 *)

%o (Python)

%o def nextd(strn, d):

%o n = int(strn) if strn != "" else 0

%o return n+1 if str(n+1)[0] == str(d) else int(str(d)+'0'*len(strn))

%o def aupton(term):

%o alst, aset = [0], {0}

%o lastdstr = ["" for d in range(10)]

%o for n in range(1, term+1):

%o lastdig = alst[-1]%10

%o firstdigs = set([max(lastdig-1, 0), min(lastdig+1, 9)]) - {0}

%o cands = [nextd(lastdstr[d], d) for d in firstdigs]

%o m = min(cands)

%o argmin = cands.index(m)

%o alst.append(m)

%o strm = str(m)

%o lastdstr[int(strm[0])] = strm

%o return alst

%o print(aupton(76)) # _Michael S. Branicky_, Feb 23 2021

%Y Cf. A001477, A000027, A341692, A341002, A331163, A331375.

%Y Cf. A131835, A217394, A217395, A217397, A217398, A217399, A217400, A217401, A217402.

%K nonn,base

%O 0,3

%A _Scott R. Shannon_, Feb 23 2021