OFFSET
1,3
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[n_] := Block[{}, If[ FromDigits[ Reverse[ IntegerDigits[n^n]]] == n^n, 0, NextPalindrome[n^n] - n^n]];
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Jason Earls, Jul 24 2003
EXTENSIONS
Edited and extended by Robert G. Wilson v, Jul 26 2003
STATUS
approved