|
|
A366958
|
|
Numbers whose difference between the largest and smallest digits is equal to 1.
|
|
8
|
|
|
10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98, 100, 101, 110, 112, 121, 122, 211, 212, 221, 223, 232, 233, 322, 323, 332, 334, 343, 344, 433, 434, 443, 445, 454, 455, 544, 545, 554, 556, 565, 566, 655, 656, 665, 667, 676, 677, 766, 767, 776, 778, 787, 788
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,1
|
|
COMMENTS
|
The number of n-digit terms of this sequence is 17*A000225(n-1).
|
|
LINKS
|
|
|
MATHEMATICA
|
Select[Range[800], Max[d=IntegerDigits[#]]-Min[d]==1 &]
|
|
PROG
|
(PARI) isok(n) = my(d=digits(n)); vecmax(d) - vecmin(d) == 1; \\ Michel Marcus, Oct 30 2023
(Python)
def ok(n): return max(d:=list(map(int, str(n))))-min(d) == 1
(Python) # faster version for large terms
from itertools import count, islice, product
def agen(diff=1): # generator of terms; change diff for A366960-A366966
for digits in count(2):
s = set()
for lo in range(10-diff):
hi = lo + diff
allowed = list(range(lo, hi+1))
for p in product(allowed, repeat=digits):
if p[0]==0 or lo not in p or hi not in p: continue
s.add(int("".join(map(str, p))))
yield from sorted(s)
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base,easy
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|