%I #22 Jul 13 2013 12:03:44
%S 1,1,1,2,2,1,1,3,3,1,2,2,2,1,1,4,4,1,1,2,2,2,1,3,3,1,2,2,2,1,1,5,5,1,
%T 1,2,2,2,1,3,3,1,3,2,2,2,1,4,4,1,1,2,2,2,2,3,3,1,2,2,2,1,1,6,6,1,1,2,
%U 2,2,1,3,3,2,2,2,2,1,1,4,4,1,2,2,2,3
%N Curling number of binary expansion of n.
%C Given a string S, write it as S = XYY...Y = XY^k, where X may be empty, and k is as large as possible; then k is the curling number of S.
%C A212439(n) = 2 * n + a(n) mod 2. - _Reinhard Zumkeller_, May 17 2012
%H Reinhard Zumkeller, <a href="/A181935/b181935.txt">Table of n, a(n) for n = 0..8191</a>
%H Benjamin Chaffin and N. J. A. Sloane, <a href="http://neilsloane.com/doc/CNC.pdf">The Curling Number Conjecture</a>, preprint.
%e 731 = 1011011011 in binary, which we could write as XY^2 with X = 10110110 and Y = 1, or as XY^3 with X = 1 and Y = 011. The latter is better, giving k = 3, so a(713) = 3.
%o (Haskell)
%o import Data.List (unfoldr, inits, tails, stripPrefix)
%o import Data.Maybe (fromJust)
%o a181935 0 = 1
%o a181935 n = curling $ unfoldr
%o (\x -> if x == 0 then Nothing else Just $ swap $ divMod x 2) n where
%o curling zs = maximum $ zipWith (\xs ys -> strip 1 xs ys)
%o (tail $ inits zs) (tail $ tails zs) where
%o strip i us vs | vs' == Nothing = i
%o | otherwise = strip (i + 1) us $ fromJust vs'
%o where vs' = stripPrefix us vs
%o -- _Reinhard Zumkeller_, May 16 2012
%Y Cf. A212412 (parity), A212440, A212441, A007088, A090822, A224764/A224765 (fractional curling number).
%K nonn,base
%O 0,4
%A _N. J. A. Sloane_, Apr 02 2012