A366198 Any a(n) replacing the first digit of a(n+1) forms a palindrome. This is the lexicographically earliest sequence of distinct nonnegative integers with this property.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 11, 21, 12, 31, 13, 41, 14, 51, 15, 61, 16, 71, 17, 81, 18, 91, 29, 22, 32, 23, 42, 24, 52, 25, 62, 26, 72, 27, 82, 28, 92, 39, 33, 43, 34, 53, 35, 63, 36, 73, 37, 83, 38, 93, 49, 44, 54, 45, 64, 46, 74, 47, 84, 48, 94, 59, 55, 65, 56, 75, 57, 85, 58, 95
Offset: 1
Examples
a(9) = 8 replacing the first digit of a(10) = 9 forms 8, a palindrome; a(10) = 9 replacing the first digit of a(11) = 19 forms 99, a palindrome; a(11) = 19 replacing the first digit of a(12) = 11 forms 191, a palindrome; a(12) = 11 replacing the first digit of a(13) = 21 forms 111, a palindrome; a(13) = 21 replacing the first digit of a(14) = 12 forms 212, a palindrome; etc.
Links
- Michael S. Branicky, Table of n, a(n) for n = 1..10000
Programs
-
Mathematica
terms=75; b[0]=0; b[n_]:=b[n]=(k=1; While[MemberQ[Array[b,n-1],k]||!PalindromeQ[FromDigits@Flatten@ReplacePart[IntegerDigits@k,1-> IntegerDigits@b[n-1]]],k++]; k); t=0;While[Length[a=Join[Range[0,9],Flatten@Table[FromDigits@Flatten@Insert[#,Table[9,i],-2]&/@(IntegerDigits/@Array[b,9^2,10]),{i,0,t++}]]]
Giorgos Kalogeropoulos, Oct 04 2023 *) -
Python
from itertools import count, islice def ispal(n): return (s:=str(n))==s[::-1] def agen(): # generator of terms an, seen = 0, set() while True: yield an; seen.add(an); s = str(an) an = next(k for k in count(0) if k not in seen and ispal(s+str(k)[1:])) print(list(islice(agen(), 80))) # Michael S. Branicky, Oct 04 2023
-
Python
# faster version suitable for generating b-file from sympy import isprime from itertools import count, islice, product def pals(digs): yield from digs for d in count(2): for p in product(digs, repeat=d//2): left = "".join(p) for mid in [[""], digs][d%2]: yield left + mid + left[::-1] def folds(s): # generator of suffixes of palindromes starting with s for i in range((len(s)+1)//2, len(s)+1): for mid in [True, False]: t = s[:i] + (s[:i-1][::-1] if mid else s[:i][::-1]) if t.startswith(s): yield t[len(s):] yield from ("".join(p)+s[::-1] for p in pals("0123456789")) def agen(): s, seen = "0", {"0"} while True: yield int(s) found = False for end in folds(s): for start in "123456789": t = start + end if t not in seen: found = True; break if found: break s, seen = t, seen | {t} print(list(islice(agen(), 60))) # Michael S. Branicky, Oct 04 2023
Formula
For n >= 92, a(n) = 10*a(n-81) + 90 - 9*(a(n-81) mod 10). - David A. Corneth, Oct 04 2023
Comments