Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The following worked for me, after a little dance around to understand what happens:

from sage.combinat.words.suffix_trees import DecoratedSuffixTree as DST

for case in range(1, 11):
    with open(f'/home/dan/Downloads/mpera/{case}.txt', 'r') as f:
        s = f.read().replace('\n', '')

    sq_vocabulary = DST(Word(s)).square_vocabulary()
    sq_vocabulary.sort(key=lambda x: (x[1], x[0]), reverse=True)
    start, square_string_len = sq_vocabulary[0]
    print(case, square_string_len/2, start)

(The zip file was downloaded, then unpacked under /home/dan/Downloads/mpera.)

Results:

1 5 5
2 8 387
3 14 3947
4 10 18374
5 19 285340
6 157 312
7 3663 12673
8 115 0
9 102971 80
10 355765 19558