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


Groups > comp.lang.python > #80310

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 04:00 +0000
Organization A noiseless patient Spider
Message-ID <m3erp6$dhn$9@dont-email.me> (permalink)
References <1962053862.5573720.1415210715670.JavaMail.zimbra@estudiantes.uci.cu> <mailman.15514.1415213345.18130.python-list@python.org> <m3eqc8$dhn$8@dont-email.me>

Show all headers | View raw


On Thu, 06 Nov 2014 03:36:40 +0000, Denis McMahon wrote:

> On Wed, 05 Nov 2014 18:49:01 +0000, MRAB wrote:
> 
>> It doesn't work for the final example or "barbaz".
> 
> Oh, and we really need a private "python homework answers" list where we
> can discuss the most pythonic solution we can think of for all these
> homework / coursework questions without showing the solutions to the
> students.

> I'm quite proud of a 2 line solution to the third algorithm that I
> implemented, although it might be considered as somewhat obfuscated code
> by some. ;)

Even prouder of the 1 liner!

In fact I'm going to post it, because I think any student who can walk 
his instructor through how my one-liner works deserves the marks. Of 
course, any student who presents this as a solution and is unable to walk 
their instructor through it should be failed for stupidity and plagiarism!

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

def baseword(s):
    """find shortest sequence which repeats to generate s"""
    return s[0:["".join([s[0:x]for k in range(int(len(s)/x)+1)])[0:len
(s)]for x in range(1,len(s)+1)].index(s)+1]

for w in t:

    print(baseword(w))

p.s. I really want to be in the room when the instructor asks this 
student to come up in front of the class and explain how his solution 
works!

-- 
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