I'm working with a list of lists that have the periods of continued fractions for non-perfect 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....]
]
The two similar methods that I've been working with are:
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
These both take the size of the lists and compare indexed sizes of it from the current position. The problem is first one returns wrong for just one repeating digit because it starts big and see's just the one large pattern. The problem with the second is that there are nested patterns like the sixth and seventh example list and it will be satisfied with the nested loop and overlook the rest of the pattern.