Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80305

Re: I need algorithm for my task

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.python
Subject Re: I need algorithm for my task
Date 2014-11-06 03:14 +0000
Organization A noiseless patient Spider
Message-ID <m3ep28$dhn$7@dont-email.me> (permalink)
References <1962053862.5573720.1415210715670.JavaMail.zimbra@estudiantes.uci.cu> <mailman.15514.1415213345.18130.python-list@python.org>

Show all headers | View raw


On Wed, 05 Nov 2014 18:49:01 +0000, MRAB wrote:

> On 2014-11-05 18:05, C@rlos wrote:
>> I thing this work:
>>
>> stg='pythonpython'
>> foundationline=stg[ 0:( stg [ 1: ].index( stg[ 0 ])+1 ) ]
>>
> It doesn't work for the final example or "barbaz".

I have two algorithms I've implemented.

Still not sure exactly which algorithm he wants though. The first one is 
as he describes, in that the word is only reported if it's repeated, else 
report the whole string.

The second algorithm reads up until the first letter is repeated, or 
reports the whole string if no repeat found.

I did see a third algorithm suggested, I should add that and see what 
happens.

OK, implemented the third algorithm (repeat first n chars of s int(n/len
(s))+1 times, truncate to len(s) and compare with s), I also added 
another test case, now my test cases are:

t = ["pythonpythonpyth", "DOLORIUMD", "HELLOLHELLO", "thewordword", 
"barbaz", "dibdibdobdibdibdob"]

and my output is:

$ ./words.py

python DOLORIUMD HELLOLHELLO thewordword barbaz dib

python DOLORIUM HELLOL thewordword bar dib

python DOLORIUM HELLOL thewordword barbaz dibdibdob

$

I wonder which of these three is actually the algorithm the OP wants.

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: I need algorithm for my task MRAB <python@mrabarnett.plus.com> - 2014-11-05 18:49 +0000
  Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 03:14 +0000
  Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 03:36 +0000
    Re: I need algorithm for my task Chris Angelico <rosuav@gmail.com> - 2014-11-06 14:47 +1100
    Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 04:00 +0000
      Re: I need algorithm for my task Chris Angelico <rosuav@gmail.com> - 2014-11-06 15:14 +1100
        Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 04:39 +0000
          Re: I need algorithm for my task Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-11-06 09:59 +0200
            Re: I need algorithm for my task wxjmfauth@gmail.com - 2014-11-06 00:57 -0800

csiph-web