# I need algorithm for my task

Denis McMahon denismfmcmahon at gmail.com
Wed Nov 5 16:19:39 CET 2014

```On Wed, 05 Nov 2014 03:58:33 -0800, lordvital21 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.

Well, the way you describe it:

So first you want to check if the first letter is also the second letter
Then you want to check if the first 2 letters are also the 3rd and 4th
Then you want to check if the first 3 letters are also the 4th-6th
Then you want to check if the first 4 letters are also the 5th-8th

So generally you want to check if the first n letters are also the second
n letters, increasing n by 1 at a time until you reach your terminating
condition.

So what is your terminating condition? I can see two possibilities. You
run out of letters in the second section, or you find a match.

Here are a few more hints to help get you started:

A string is a list of characters.
A list can be sliced.
You can measure the length of a list.
You can compare the lengths of two lists.
You can compare two lists.
You can get the length of a string.
The maximum length of a repeated word in a string can not be more than
half the length of the string.

However, the examples you give do not match the way you describe it. The
examples you give assume the first word ends when the letter that started
it is found again.

--
Denis McMahon, denismfmcmahon at gmail.com

```