I have a list of numbers, for example:
list= [1, 2, 4, 1, 2, 4, 1, 2, 4]
You can see the obvious repeating pattern of 1,2,4
I'm trying to find a way to go through that list to determine the cycle and it's length. The numbers vary every time in my program. So for example, the list that I give, I want it to output 3, which is the length of the pattern.
I tried comparing the items together, but ultimately couldn't figure out a way to do it efficiently without going out of the list index every time, because I was just looking for when a number repeated in the sequence. The problem with that was that the pattern could be something like 2 2 1, in which case i would have outputted 2 as the pattern length, when it was actually 3.
Sorry for the lack of information, I'm lost as to how to do this so I don't have much sample code to show.
[1,2,3,1,2,3,1,2,3,1]a valid list?