login
Numbers with monotonically increasing digits, increasing by only 0 or 1.
1

%I #21 Jan 19 2025 00:36:36

%S 1,2,3,4,5,6,7,8,9,11,12,22,23,33,34,44,45,55,56,66,67,77,78,88,89,99,

%T 111,112,122,123,222,223,233,234,333,334,344,345,444,445,455,456,555,

%U 556,566,567,666,667,677,678,777,778,788,789,888,889,899,999

%N Numbers with monotonically increasing digits, increasing by only 0 or 1.

%H Robert Israel, <a href="/A378949/b378949.txt">Table of n, a(n) for n = 1..10000</a>

%e 33 is a term since the digits are monotonically increasing and their difference is 0.

%e 34 is also a term since the digits are monotonically increasing and their difference is 1.

%e 35 is not a term since the difference in consecutive digits is not 0 or 1.

%e 32 is not a term since the digits are decreasing.

%p extend:= proc(k) local m,d;

%p m:= 10^ilog10(k);

%p d:= floor(k/m);

%p if d = 1 then 10*m+k else (d-1)*10*m+k, d*10*m+k fi

%p end proc:

%p R:= $1..9:

%p A:= [R]:

%p for i from 2 to 5 do

%p A:= map(extend,A);

%p R:= R, op(sort(A));

%p od:

%p R; # _Robert Israel_, Jan 18 2025

%t Select[Range[1000],SubsetQ[{0, 1}, Union@ Differences@ IntegerDigits[#]] &] (* _James C. McMahon_, Dec 21 2024 *)

%o (Python)

%o from itertools import count, islice

%o def bgen(last, d):

%o if d == 0: yield tuple(); return

%o t = (1, 9) if last == None else (last, min(last+1, 9))

%o for i in range(t[0], t[1]+1): yield from ((i, )+r for r in bgen(i, d-1))

%o def agen(): # generator of terms

%o yield from (int("".join(map(str, i))) for d in count(1) for i in bgen(None, d))

%o print(list(islice(agen(), 62))) # _Michael S. Branicky_, Dec 18 2024

%Y Cf. A378808, A378774.

%K nonn,base

%O 1,2

%A _Randy L. Ekl_, Dec 18 2024

%E Offset corrected by _James C. McMahon_, Dec 21 2024