Re: Exercises please

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Exercises please
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.lisp
Date : 21. Jun 2025, 22:12:02
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250621140023.834@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-06-21, B. Pym <Nobody447095@here-nor-there.org> wrote:
Pascal J. Bourguignon wrote:
>
and my solutions (still incomplete):
http://www.informatimago.com/develop/lisp/l99/index.html
>
Where we find:
>
(---------------------------------------------------------------
P13 (**) Run-length encoding of a list (direct solution).
>
   Example:
    * (encode-direct '(a a a a b c c a a d e e e e))
    ((4 A) B (2 C) (2 A) D (4 E))
"

1> (flow '(a a a a b c c a a d e e e e)
     (partition-by identity)
     (map [juxt car len]))
((a 4) (b 1) (c 2) (a 2) (d 1) (e 4))

Oops.

2> (flow '(a a a a b c c a a d e e e e)
     (partition-by identity)
     (map [juxt len car]))
((4 a) (1 b) (2 c) (2 a) (1 d) (4 e))

Oops.

3> (flow '(a a a a b c c a a d e e e e)
     (partition-by identity)
     (mapcar [iff cdr [juxt len car] car]))
((4 a) b (2 c) (2 a) d (4 e))

I get working code before I'm done properly scanning the requirements and can
fix it in a few keystrokes.

Shorter:


;; Iterative solution, uses only O(r) space:

TL; DR.

Date Sujet#  Auteur
21 Jun 25 * Re: Exercises please2B. Pym
21 Jun 25 `- Re: Exercises please1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal