A357142 Nonnegative numbers all of whose pairs of consecutive decimal digits are adjacent digits, where 9 and 0 are considered adjacent.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 90, 98, 101, 109, 121, 123, 210, 212, 232, 234, 321, 323, 343, 345, 432, 434, 454, 456, 543, 545, 565, 567, 654, 656, 676, 678, 765, 767, 787, 789, 876, 878, 890, 898, 901, 909
Offset: 1
Programs
-
Maple
q:= n-> (l-> andmap(x-> x in {1, 9}, {seq(abs(l[i]-l[i-1]), i=2..nops(l))}))(convert(n, base, 10)): select(q, [$0..1000])[]; # Alois P. Heinz, Sep 14 2022
-
Mathematica
q[n_] := AllTrue[Abs @ Differences @ IntegerDigits[n], MemberQ[{1, 9}, #] &]; Select[Range[0, 1000], q] (* Amiram Eldar, Sep 15 2022 *)
-
PARI
a(n) = { n--; for (b=0, oo, if (n <= 9*2^b, my (v=ceil(n/2^b), p=(n-1)%(2^b)); while (b>0, v=10*v+vecsort([(v-1)%10, (v+1)%10])[1+bittest(p,b--)];); return (v), n -= 9*2^b)) } \\ Rémy Sigrist, Sep 15 2022
-
Python
def add_dig(x): d = (x%10-1)%8 if x%10 != 0 else 1 return 10*x+d def try_incr(x): if x < 10: return x+1 r = x//10 d2 = r%10 d = max((d2+1)%10,(d2-1)%10) return 10*r+d def incr(x): new_x=try_incr(x) return new_x if new_x>x else add_dig(incr(x//10)) x = 0 for n in range(1,1000): print(f"{n} {x}") x = incr(x)
Comments