What is the best way to find the period in a repeating list?
For example:
a = {4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2}
has repeat
I propose this. It borrows from both Verbeia and Brett's answers.
Do[
If[MatchQ @@ Equal @@ Partition[#, i, i, 1, _], Return @@ i],
{i, #[[ 2 ;; Floor[Length@#/2] ]] ~Position~ First@#}
] /. Null -> $Failed &
It is not quite as efficient as Vebeia's function on long periods, but it is faster on short ones, and it is simpler as well.