OFFSET
1,3
LINKS
Robert Israel, Table of n, a(n) for n = 1..243
EXAMPLE
66 in base 2 is 1000010, which is palindromic if rewritten as 01000010.
MAPLE
nextpal:= proc(p, d, V, b)
local i, i2, pp, m, m2;
pp:=p;
V[1]:= V[1]+1;
m2:= floor(d/2);
i2:= ceil(d/2);
if d::odd then pp:= pp + b^m2 else pp:= pp + b^m2 + b^(m2-1) fi;
for i from 1 while V[i] = b do
V[i]:= 0:
if i = i2 then
if d::even then
ArrayTools:-Extend(V, [1], inplace);
return b^d+1, d+1, V
else
V[i2]:= 1;
return b^d+1, d+1, V;
fi;
fi;
V[i+1]:= V[i+1]+1;
if (d::odd and i=1) then pp:= pp + b^(i2-i-1) else
pp:= pp + b^(i2-i-1) - b^(i2-i+1) fi;
od;
return pp, d, V
end proc:
count:= 1:
S:= 0:
p2[0]:=1: V2[0]:= <1>: d2[0]:= 1:m2:= 0:
p10[0]:= 1: V10[0]:= <1>: d10[0]:= 1: m10:= 0:
while count < 100 do
i2:= min[index]([seq(p2[i], i=0..m2)])-1; p2o:= p2[i2];
i10:= min[index]([seq(p10[i], i=0..m10)])-1; p10o:= p10[i10];
if p2o = p10o then
S:= S, p2o; count:= count+1;
fi;
if p2o <= p10o then x, d2[i2], V2[i2]:= nextpal(p2o/2^i2, d2[i2], V2[i2], 2); p2[i2]:= 2^i2 *x;
if i2 = m2 then m2:= m2+1; p2[m2]:= 2^m2; V2[m2]:= <1>; d2[m2]:= 1;
fi;
else
x, d10[i10], V10[i10]:= nextpal(p10o/10^i10, d10[i10], V10[i10], 10);
p10[i10]:= 10^i10 * x;
if i10 = m10 then m10:= m10+1; p10[m10]:= 10^m10; V10[m10]:= <1>; d10[m10]:= 1
fi fi od:
S; # Robert Israel, Apr 01 2024
MATHEMATICA
pal[n_, b_] := (z=IntegerDigits[n, b]) == Reverse[z]; extpal[n_, b_] := If[Mod[n, b]>0, pal[n, b], extpal[n/b, b]]; Select[Range[50000], extpal[ #, 10]&&extpal[ #, 2]&]
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Amarnath Murthy, Apr 02 2002
EXTENSIONS
Edited by Dean Hickerson, Apr 06 2002
0 inserted by Sean A. Irvine, Mar 29 2024
STATUS
approved