%I #40 Oct 31 2013 12:17:17
%S 1,1,2,2,3,2,3,3,4,3,3,2,3,3,4,4,5,4,4,3,5,4,3,3,4,3,5,3,3,4,5,5,6,5,
%T 5,5,4,4,4,3,4,5,5,4,6,5,4,4,5,4,6,3,5,5,5,3,4,3,5,4,4,5,6,6,7,6,6,5,
%U 5,5,5,5,7,5,4,6,4,5,4,4,5,6,4,5,7,5,5,4,4,6,6,5,7,6,5,5,6,5,7,5,4,6,6,3,4
%N Length of longest palindromic subword of (n base 2).
%C a(A083318(n-1)) = n; a(A193159(k)) = 3, 1 <= k <= 26. [_Reinhard Zumkeller_, Jul 17 2011]
%H Reinhard Zumkeller, <a href="/A050430/b050430.txt">Table of n, a(n) for n = 1..16385 = 2^14 + 1 </a>
%F a(n) <= min(a(2*n), a(2*n+1)). [_Reinhard Zumkeller_, Jul 31 2011]
%e (11 base 2) = 1011, containing the palindrome 101, therefore a(11) = 3.
%p # A050430 Length of longest palindromic factor of n for n in [M1..M2] - from _N. J. A. Sloane_, Aug 07 2012, revised Aug 11 2012
%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 # start of main program
%p ans:=[];
%p M1:=0; M2:=64;
%p for n from M1 to M2 do
%p t1:=convert(n,base,2);
%p rec:=0:
%p l1:=nops(t1);
%p for j1 from 0 to l1-1 do
%p for j2 from j1+1 to l1 do
%p F1 := [op(j1+1..j2,t1)];
%p if (isPal(F1) and j2-j1>rec) then rec:=j2-j1; fi;
%p od:
%p od:
%p ans:=[op(ans),rec]:
%p od:
%p ans;
%t f[n_] := Block[{id = IntegerDigits[n, 2]}, k = Length@ id; While[ Union[# == Reverse@# & /@ Partition[id, k, 1]][[-1]] != True, k--]; k]; Array[f, 105] (* _Robert G. Wilson v_, Jul 16 2011 *)
%o (Haskell)
%o import Data.Char (intToDigit, digitToInt)
%o import Numeric (showIntAtBase)
%o a050430 n = a050430_list !! (n-1)
%o a050430_list = f 1 where
%o f n = g (showIntAtBase 2 intToDigit n "") : f (n+1)
%o g zs | zs == reverse zs = length zs
%o | otherwise = max (h $ init zs) (h $ tail zs)
%o h zs@('0':_) = g zs
%o h zs@('1':_) = a050430 $ foldl (\v d -> digitToInt d + 2*v) 0 zs
%o -- _Reinhard Zumkeller_, Jul 16 2011
%Y Cf. A007088; A050431 (base 3), A050432 (base 4), A050433 (base 5).
%Y Cf. A215244, A215467, A215256.
%K nonn,base
%O 1,3
%A _Clark Kimberling_
%E Extended by _Ray Chandler_, Mar 11 2010
|