| Deutsch English Français Italiano |
|
<20250621140023.834@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.lisp
Subject: Re: Exercises please
Date: Sat, 21 Jun 2025 21:12:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <20250621140023.834@kylheku.com>
References: <10374hj$191qo$1@dont-email.me>
Injection-Date: Sat, 21 Jun 2025 23:12:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="40233374f8a41a710c86d069409794a7";
logging-data="1358779"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a6oblzt2C8TecLrSa2GHxa4hyS3A62Uo="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:9xvqFHITdHXRCUy5u3YFsVblVO0=
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.