|
|
A246008
|
|
Let pal(k) denote the k-th palindrome, A002113(k), and let a(0)=0 and a(1)=1. For n >= 2, if a(n-1) = pal(k), then a(n) = pal(k+i), where i = a(n-1)-a(n-2).
|
|
1
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 33, 252, 15451, 54533545, 445335474533544, 34533547453354645335474533543, 245335474533546453354745335454533547453354645335474533542, 14533547453354645335474533545453354745335464533547453354445335474533546453354745335454533547453354645335474533541
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
COMMENTS
|
If instead we set a(n) = pal(a(n-1)), the sequence would have to start at the twelfth palindrome 22, and go from there: 12, 22, 121, 2112, 1112111, 112111111211, 1211111121111211111121, 211111121111211111121121111112111121111112, ..., . This sequence is interesting in that only the digits 1 and 2 appear so far (tested out to seventeen terms).
|
|
LINKS
|
|
|
EXAMPLE
|
For n=11, we have a(10)=11=pal(11), a(10)-a(9)=11-9=2, so a(11) = pal(11+2) = pal(13) = 33.
a(12) = 252 because it is the twenty-second palindrome after 13, the difference between 11 and 33.
|
|
MATHEMATICA
|
NextPalindrome[n_] := Block[{l = Floor[ Log[ 10, n] + 1], idn = IntegerDigits[ n]}, If[ Union[ idn] == {9}, Return[n + 2], If[l < 2, Return[n + 1], If[ FromDigits[ Reverse[ Take[ idn, Ceiling[l/2]]]] > FromDigits[ Take[ idn, -Ceiling[l/2]]], FromDigits[ Join[ Take[ idn, Ceiling[l/2]], Reverse[ Take[ idn, Floor[l/2]]]]], idfhn = FromDigits[ Take[ idn, Ceiling[l/2]]] + 1; idp = FromDigits[ Join[ IntegerDigits[ idfhn], Drop[ Reverse[ IntegerDigits[ idfhn]], Mod[l, 2]]]]]]]]; f[s_List] := Block[{a = s[[-1]], b = s[[-2]]}, Append[s, Nest[ NextPalindrome@# &, a, a - b]]]; s = {0, 1}, Nest[f, s, 14]
nthPalindrome[n_] := Block[{q = n + 1 - 10^Floor[ Log10[n + 1 - 10^Floor[ Log10[ n/10]] ]], c = Sum[ Floor[ Floor[ n/(11*10^(k - 1) - 1)]/(Floor[ n/(11*10^(k - 1) - 1)] - 1/10)] - Floor[ Floor[ n/(2*10^k - 1)]/(Floor[ n/(2*10^k - 1)] - 1/10)], {k, Floor[ Log10[ n]] }]}, Mod[q, 10]*11^c*10^Floor[ Log10[ q]] + Sum[ Floor[ Mod[q, 10^(k + 1)]/10^k]*10^(Floor[ Log10[ q]] - k) (10^(2 k + c) + 1) , {k, Floor[ Log10[ q]] }]] (* after the work of Eric A. Schmidt, see A002113 *) s = {0}; f[s_List] := Block[{k = s[[-1]] + 1}, Append[s, nthPalindrome[ k]]]; Nest[f, s, 18] (* Robert G. Wilson v, Sep 22 2014 *)
|
|
PROG
|
(Python)
from itertools import islice
def A246008_gen(): # generator of terms
a, b, k = 0, 1, 2
yield 0
while True:
yield b
a, b = b, int((c:=k-x)*x+int(str(c)[-2::-1] or 0) if (k:=k+b-a)<(x:=10**(len(str(k>>1))-1))+(y:=10*x) else (c:=k-y)*y+int(str(c)[::-1] or 0))
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|