I need algorithm for my task

Peter Otten __peter__ at web.de
Wed Nov 5 07:36:17 EST 2014


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.

A simple approach that might work (I didn't implement it to verify):

Look for other occurences of the first letter. If there are none you have 
the "foundation", if there are any, split the line before them and check if 
the rest of the line can be constructed as a (possibly truncated) repetition 
of the beginning. For

fifafofifaf

you'd have to check

fi fafofifaf --> false
fifa fofifaf --> false
fifafo fifaf --> true

so we don't care about

fifafofi faf
fifafofifa f





More information about the Python-list mailing list