What is the best way to find the period of a (repeating) list in Mathematica?

Posted by Arnoud Buzing on Stack Overflow See other posts from Stack Overflow or by Arnoud Buzing
Published on 2011-11-18T00:56:17Z Indexed on 2011/11/19 9:50 UTC
Read the original article Hit count: 126

Filed under:
|

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 {4, 5, 1, 2, 3} with the remainder {4, 5, 1, 2} matching, but being incomplete.

The algorithm should be fast enough to handle longer cases, like so:

b = RandomInteger[10000, {100}];
a = Join[b, b, b, b, Take[b, 27]]

The algorithm should return $Failed if there is no repeating pattern like above.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about mathematica