[Haskell-cafe] Period of a sequence

Henning Thielemann schlepptop at henning-thielemann.de
Sat Jul 2 18:44:24 CEST 2011


On 26.06.2011 16:16, michael rice wrote:
> MathWorks has the function seqperiod(x) to return the period of sequence
> x. Is there an equivalent function in Haskell?

seqperiod x = fst $ head $ filter (flip List.isPrefixOf x . snd) $ tail 
$ zip [0..] $ List.tails x

This relies on the fact, that p is a period of x, if
   isPrefixOf (drop p x) x
.



More information about the Haskell-Cafe mailing list