I work with a list of lists that have periods of continued fractions for imperfect square roots in each of them.
What I'm trying to do with them is to check the size of the largest repeating pattern in each list.
Some of the lists, for example:
[ [1,1,1,1,1,1....], [4,1,4,1,4,1....], [1,2,10,1,2,10....], [1,1,1,1,1,4,1,4,1,20,9,8,1,1,1,1,1,4,1,4,1,20,9,8....], [2,2,2,4,2,2,2,4....], [1,1,1,13,21,45,3,3,1,16,4,1,4,1,1,1,24,15,1,1,1,13,21,45,3,3,1,16,4,1,4,1,1,1,24,15....], [1,1,1,3,28,1,1,1,3,28,67,25,1,1,1,3,28,1,1,1,3,28,67,25....] ]
Two similar methods that I worked with are as follows:
def lengths(seq): for i in range(len(seq),1,-1): if seq[0:i] == seq[i:i*2]: return i def lengths(seq): for i in range(1,len(seq)-1): if seq[0:i] == seq[i:i*2]: return i
They take the size of the lists and compare the indexed sizes of it with the current position. The problem is that at first it returns incorrectly for only one repeating digit, because it starts large and sees only one large pattern. The problem with the second is that there are nested patterns such as the sixth and seventh examples, and this will execute with a nested loop and ignore the rest of the pattern.