I need algorithm for my task

MRAB python at mrabarnett.plus.com
Wed Nov 5 12:53:23 EST 2014


On 2014-11-05 11:58, lordvital21 at gmail.com wrote:
> I have line 'pythonpythonpyth'. How do I know which word is the foundation line?.
> Other examples:
> "pythonpythonpyth" is python
> "DOLORIUMD" is DOLORIUM
> "HELLOLHELLO" is HELLOL
> "thewordword" is thewordword
>
> I need to know whether the word in the text is repeated and get it. This will be the key.
>
Consider the first example.

If the foundation is the first 1 character 'p' and you repeat it enough
times you'll get 'pppppppppppppppp'.

This is the same length as the line.

Does it match the line? No.

OK.

If the foundation is the first 2 characters 'py' and you repeat it
enough times you'll get 'pypypypypypypypy'.

This is the same length as the line.

Does it match the line? No.

OK.

If the foundation is the first 3 characters 'py' and you repeat it
enough times you'll get 'pytpytpytpytpytpyt'.

This is longer than as the line, so truncate it to 'pytpytpytpytpytpy'.

Does it match the line? No.

OK.

Continue in this vein until you'll get a match. (The foundation might
in fact be the entire line.)




More information about the Python-list mailing list