login
Smallest palindrome m such that n + m (m>0) is also a palindrome, or 0 if no such number exists.
2

%I #8 Jul 24 2014 17:26:29

%S 1,1,1,1,1,1,1,1,2,1,11,99,9,8,7,6,5,4,3,2,1,11,88,9,8,7,6,5,4,3,2,1,

%T 11,77,9,8,7,6,5,4,3,2,1,11,66,9,8,7,6,5,4,3,2,1,11,55,9,8,7,6,5,4,3,

%U 2,1,11,44,9,8,7,6,5,4,3,2,1,11,33,9,8,7,6,5,4,3,2,1,11,22,9,8,7,6,5,4,3

%N Smallest palindrome m such that n + m (m>0) is also a palindrome, or 0 if no such number exists.

%C The first occurrence of 0 happens at n = 919.

%e a(11) = 11, 11 + 11 = 22; a(12) = 99, 99 + 12 = 111; etc.

%o (PARI) ispal(n) = eval(concat(Vecrev(Str(n)))) == n;

%o nextpal(k) = k++; while(! ispal(k), k++); k;

%o a(n) = {m = 1; while (! ispal(n+m), m = nextpal(m)); m;} \\ _Michel Marcus_, Jul 24 2014

%Y Cf. A082273, A084843.

%K nonn,base

%O 1,9

%A _Amarnath Murthy_, Apr 13 2003

%E Edited by _Patrick De Geest_, Jun 08 2003