A050430 Length of longest palindromic subword of (n base 2).
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, 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, 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
Offset: 1
Examples
(11 base 2) = 1011, containing the palindrome 101, therefore a(11) = 3.
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 1..16385 = 2^14 + 1
Crossrefs
Programs
-
Haskell
import Data.Char (intToDigit, digitToInt) import Numeric (showIntAtBase) a050430 n = a050430_list !! (n-1) a050430_list = f 1 where f n = g (showIntAtBase 2 intToDigit n "") : f (n+1) g zs | zs == reverse zs = length zs | otherwise = max (h $ init zs) (h $ tail zs) h zs@('0':_) = g zs h zs@('1':_) = a050430 $ foldl (\v d -> digitToInt d + 2*v) 0 zs -- Reinhard Zumkeller, Jul 16 2011
-
Maple
# 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 isPal := proc(L) local d ; for d from 1 to nops(L)/2 do if op(d, L) <> op(-d, L) then return false; end if; end do: return true; end proc: # start of main program ans:=[]; M1:=0; M2:=64; for n from M1 to M2 do t1:=convert(n,base,2); rec:=0: l1:=nops(t1); for j1 from 0 to l1-1 do for j2 from j1+1 to l1 do F1 := [op(j1+1..j2,t1)]; if (isPal(F1) and j2-j1>rec) then rec:=j2-j1; fi; od: od: ans:=[op(ans),rec]: od: ans;
-
Mathematica
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 *)
Formula
a(n) <= min(a(2*n), a(2*n+1)). [Reinhard Zumkeller, Jul 31 2011]
Extensions
Extended by Ray Chandler, Mar 11 2010
Comments