Periodic Sequence

Author

Eric W. Weisstein
November 30, 2003

This notebook downloaded from http://mathworld.wolfram.com/notebooks/IntegerSequences/PeriodicSequence.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/PeriodicSequence.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Code

Period[l_List]:=Module[
{
p=NestWhileList[Rest,Rest[l],#≠Take[l,Length[#]]&,1]
},
If[Last[p]=={}||Length[p]==Length[l]-1,0,Length[p]]
]

Examples

Period[{1}]

Period[{1,1}]

Period[{1,1,1}]

Period[{1,2,1,2}]

Period[{2,1,2,1}]

Period[{1,2,3,4,1,2,3,4}]

Period[{1,1,2,1}]

Period[{1,1,2,1,1}]

Period[{2,1,1,2,1,1}]