|
|
A052037
|
|
Smallest positive number that must be added to n to reach a palindrome.
|
|
4
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,10
|
|
COMMENTS
|
The pattern breaks down as for instance 99 need be added only with 2 instead of 11.
More precisely, the pattern changes (shape and length) at n=9, n=99, n=999, etc. - M. F. Hasler, Apr 26 2014
|
|
LINKS
|
|
|
MAPLE
|
N:= 3: # to get a(0)..a(10^N)
revdigs:= proc(n) local L, j, nL;
L:= convert(n, base, 10); nL:= nops(L);
add(L[j]*10^(nL-j), j=1..nL);
end proc:
palis:= $0..9:
for d from 2 to N do
if d::even then
palis:= palis, seq(x*10^(d/2)+revdigs(x), x=10^(d/2-1)..10^(d/2)-1)
else
palis:= palis, seq(seq(x*10^((d+1)/2)+y*10^((d-1)/2)+revdigs(x), y=0..9), x=10^((d-3)/2)..10^((d-1)/2)-1);
fi
od:
palis:= [palis, (10^(N+1)-1)/9]:
f:= proc(n) local k;
k:= ListTools[BinaryPlace](palis, n);
if palis[k+1]=n then palis[k+2]-n else palis[k+1]-n fi
end proc:
|
|
MATHEMATICA
|
spn[n_]:=Module[{k=1}, While[!PalindromeQ[n+k], k++]; k]; Join[{1}, Array[spn, 100]] (* Harvey P. Dale, Mar 01 2023 *)
|
|
PROG
|
(PARI) a(n)=for(k=1, 9e19, is_A002113(n+k)&&return(k)) \\ For illustrative purpose only, inefficient for most large numbers. - M. F. Hasler, Apr 26 2014
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base,easy
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|