login
Length of longest palindromic prefix of (n base 2).
5

%I #17 Aug 12 2012 18:57:30

%S 1,1,1,2,1,3,2,3,1,4,3,3,2,2,3,4,1,5,4,4,3,5,3,3,2,2,2,5,3,3,4,5,1,6,

%T 5,5,4,4,4,4,3,3,5,5,3,6,3,3,2,2,2,6,2,2,5,5,3,3,3,3,4,4,5,6,1,7,6,6,

%U 5,5,5,5,4,7,4,4,4,4,4,4,3,3,3,3,5,7,5,5,3,3,6

%N Length of longest palindromic prefix of (n base 2).

%C Since the binary expansion of n always begins with a 1, a final 0 can't affect the result, so a(2n) = a(n).

%H N. J. A. Sloane, <a href="/A215467/b215467.txt">Table of n, a(n) for n = 0..10000</a>

%e ...

%e 4 = 100 -> 1

%e 5 = 101 -> 3

%e 6 = 110 -> 2

%e 7 = 111 -> 3

%e 8 = 1000 -> 1

%e 9 = 1001 -> 4

%e ...

%p rev := proc(lis)

%p local t1,n,i;

%p t1:=[]; n:=nops(lis);

%p for i from 1 to n do t1:=[op(t1),lis[n+1-i]]; end do;

%p return t1;

%p end proc;

%p isPal := proc(L)

%p local d ;

%p for d from 1 to nops(L)/2 do

%p if op(d, L) <> op(-d, L) then

%p return false;

%p end if;

%p end do:

%p return true;

%p end proc:

%p A215467L := proc(L)

%p local a, c;

%p a := 1 ;

%p for c from 2 to nops(L) do

%p if isPal( [op(1..c, L)] ) then

%p a := c ;

%p end if;

%p end do:

%p return a;

%p end proc:

%p A215467 := proc(n)

%p if n <= 1 then 1;

%p else rev(convert(n, base, 2)) ;

%p A215467L(%) ;

%p end if;

%p end proc:

%Y Cf. A050430, A215469.

%K nonn,base

%O 0,4

%A _N. J. A. Sloane_, Aug 11 2012