OFFSET
1,3
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
EXAMPLE
As a(1) to a(10) are single-digit palindromes, the replacement leaves the terms a(1) to a(10) as they were.
a(11) = 11 and we must replace the first digit d = 1 of 11 by the smallest base-10 palindrome not yet used; this is 11 (as the palindrome 1 has been used before);
a(11) = 11 and we must replace now the second digit d = 1 of 11 by the smallest base-10 palindrome not yet used; this is 101 (as 1 and 11 have been used before);
a(12) = 101 and we must replace the first digit d = 1 of 101 by the smallest base-10 palindrome not yet used; this is 111;
a(12) = 101 and we must now replace the digit d = 0 of 101 by the smallest base-10 palindrome not yet used; this is 202 (as 0 and 101 have been used before);
a(12) = 101 and we must now replace the last digit d = 1 of 101 by the smallest base-10 palindrome not yet used; this is 121; etc.
PROG
(Python)
from collections import deque
from itertools import count, islice
def pals(start=1): # generator of palindromes >= palindrome start
s = str(start)
q, r = divmod(len(s)+1, 2)
for d in count(q):
olst = [1, 0][int(d==q and r==1):]
for offset in olst:
lb = max(1, 10**(d-1)) if d>q or offset!=olst[0] else int(s[:q])
for i in range(lb, 10**d):
left = str(i)
yield int(left+left[::-1][offset:])
def agen(): # generator of terms
S = deque([101])
head = list(range(10)) + [11]
yield from head
used = set(head) | {101}
pstart = {d:0 for d in "0123456789"}
while True:
an = S.popleft()
yield an
for d in str(an):
p = next(p for p in pals(start=pstart[d]) if p not in used and d in str(p))
pstart[d] = p
S.append(p)
used.add(p)
print(list(islice(agen(), 57))) # Michael S. Branicky, Mar 03 2024
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Eric Angelini, Mar 02 2024
EXTENSIONS
More terms from Michael S. Branicky, Mar 03 2024
STATUS
approved