cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A050430 Length of longest palindromic subword of (n base 2).

This page as a plain text file.
%I A050430 #40 Oct 31 2013 12:17:17
%S A050430 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 A050430 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 A050430 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 A050430 Length of longest palindromic subword of (n base 2).
%C A050430 a(A083318(n-1)) = n; a(A193159(k)) = 3, 1 <= k <= 26. [_Reinhard Zumkeller_, Jul 17 2011]
%H A050430 Reinhard Zumkeller, <a href="/A050430/b050430.txt">Table of n, a(n) for n = 1..16385 = 2^14 + 1 </a>
%F A050430 a(n) <= min(a(2*n), a(2*n+1)). [_Reinhard Zumkeller_, Jul 31 2011]
%e A050430 (11 base 2) = 1011, containing the palindrome 101, therefore a(11) = 3.
%p A050430 # 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 A050430 isPal := proc(L)
%p A050430     local d ;
%p A050430     for d from 1 to nops(L)/2 do
%p A050430         if op(d, L) <> op(-d, L) then
%p A050430             return false;
%p A050430         end if;
%p A050430     end do:
%p A050430     return true;
%p A050430 end proc:
%p A050430 # start of main program
%p A050430 ans:=[];
%p A050430 M1:=0; M2:=64;
%p A050430 for n from M1 to M2 do
%p A050430 t1:=convert(n,base,2);
%p A050430 rec:=0:
%p A050430 l1:=nops(t1);
%p A050430 for j1 from 0 to l1-1 do
%p A050430 for j2 from j1+1 to l1 do
%p A050430 F1 := [op(j1+1..j2,t1)];
%p A050430 if (isPal(F1) and j2-j1>rec) then rec:=j2-j1; fi;
%p A050430 od:
%p A050430 od:
%p A050430 ans:=[op(ans),rec]:
%p A050430 od:
%p A050430 ans;
%t A050430 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 A050430 (Haskell)
%o A050430 import Data.Char (intToDigit, digitToInt)
%o A050430 import Numeric (showIntAtBase)
%o A050430 a050430 n = a050430_list !! (n-1)
%o A050430 a050430_list = f 1 where
%o A050430    f n = g (showIntAtBase 2 intToDigit n "") : f (n+1)
%o A050430    g zs | zs == reverse zs = length zs
%o A050430         | otherwise        = max (h $ init zs) (h $ tail zs)
%o A050430    h zs@('0':_) = g zs
%o A050430    h zs@('1':_) = a050430 $ foldl (\v d -> digitToInt d + 2*v) 0 zs
%o A050430 -- _Reinhard Zumkeller_, Jul 16 2011
%Y A050430 Cf. A007088; A050431 (base 3), A050432 (base 4), A050433 (base 5).
%Y A050430 Cf. A215244, A215467, A215256.
%K A050430 nonn,base
%O A050430 1,3
%A A050430 _Clark Kimberling_
%E A050430 Extended by _Ray Chandler_, Mar 11 2010