login
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
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:
map(f, [$0..10^N]); # Robert Israel, Jan 08 2018
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
Patrick De Geest, Dec 15 1999
EXTENSIONS
Edited by N. J. A. Sloane, Jan 17 2009 at the suggestion of R. J. Mathar
STATUS
approved