Suppose we have a recurrent process. And we know for sure that it is *cyclical.* That it has a period.

How do I find this period using Wolfram Mathematica?

An example process is provided here.

I am using code like this:

`iteratedStates[init_]: = NestWhileList[process[#]&, init, Unequal, All]; period[init_]: = With[{data = iteratedStates[init]}, First@Differences@Flatten@Position[data, Last@data] ]; `

It is not effective. I tried to implement various algorithms but their implementations were even slower ((

UPD. Yes, there is `FindTransientRepeat`

But here what we have:

`data = ContinuedFraction[(Sqrt[12] + 2)/7, 10004]; Timing[Length@Last@FindTransientRepeat[data, 2]] {0.0624004, 6} Timing[First@Differences@Flatten@Position[data, Last@data]] {0.0156001, 6} `

I *need* store all data. So `NestWhileList`

is needed. And it seems that my implementation is good enough