Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]

Liste des GroupesRevenir à cl lisp 
Sujet : Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.lisp
Date : 17. Feb 2025, 08:44:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <878qq5582x.fsf@nightsong.com>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Madhu <enometh@meer.net> writes:
FWIW My code is pretty clunky, somehow TIME SBCL says it conses 0 bytes
when I run it on individual words without interning although when I'm
explicitly manipulating plists and arrays.

Yikes.  I did a Python version that conses a lot but is fairly concise,
I thought.  From the looks of things, your /usr/share/dict/words is
larger than mine.  Mine has about 100k entries and this code took about
0.7 seconds on my laptop, not great, but obviously many optimizations
are possible with the same basic approach:

    from collections import defaultdict

    def runlen(word:str) -> int:
        d = defaultdict(int)
        def pred(c): return chr(ord(c)-1) # unicode predecessor
        for c in word:
            d[c] = d[pred(c)] + 1
        return max((n,c) for c,n in d.items())

    def main():
        for w in open('/usr/share/dict/words'):
            n,c = runlen(w.strip())
            if n>=5: print(w.strip(),n,c)

    main()

Date Sujet#  Auteur
15 Feb 25 * ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]17HenHanna
16 Feb 25 +- Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]1Lawrence D'Oliveiro
16 Feb 25 +* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]4Richard Tobin
16 Feb 25 i`* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]3Paul Rubin
16 Feb 25 i +- Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]1HenHanna
16 Feb 25 i `- Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]1Richard Tobin
16 Feb 25 +* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]10Madhu
16 Feb 25 i`* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]9Paul Rubin
16 Feb 25 i +- Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]1Paul Rubin
16 Feb 25 i `* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]7Madhu
16 Feb 25 i  +* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]3HenHanna
17 Feb 25 i  i`* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]2Madhu
17 Feb 25 i  i `- Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]1HenHanna
16 Feb 25 i  `* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]3Paul Rubin
17 Feb 25 i   `* Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]2Madhu
17 Feb 25 i    `- Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]1Paul Rubin
16 Feb 25 `- Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]1Carl G.

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal