function V=palindro(N);
% Palindrome number generator
% Format:  V=palindro(N)
% Input:
%   N any integer
%   V a vector of ouput results, with the
% Output: Solution vector,  final element is a palindrome 
%   e.g., 1754571, or NaN if numeric accuracy exceeded.
%   Algorithm:
%   if N is a palindrome  (e.g., 12321)  return V=N
%   if N isn't a palindrome then
%     flip N left to right (e.g., 123 => 321) and
%    add to N.  Repeat until a palindrome number
%    is achieved or until N>1e15
%   Written by E. Gallagher 10/10/96.
%   See also palindvp.m for symbolic
iter=100; %1e15 will be hit long before this iteration limit
V=zeros(iter,1);
V(1,1)=N;
for i=2:2:iter-1
    V(i,1)=round(eval(fliplr(sprintf('%16.0f',V(i-1,1)))));
    if V(i,1)==V(i-1,1) | V(i,1)>1e15
%      Matlab double precision only 16 significant figures
       if(V(i)>1e15);
             V=NaN;
       else
              V(i)=0;
              V=V(~(~V));
       end
       break
    else
       V(i+1,1)=V(i,1)+V(i-1,1);
    end
end
