Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Someone is speaking well of you.


comp / comp.lang.lisp / Rosetta Code: Sort disjoint sublist

SubjectAuthor
o Rosetta Code: Sort disjoint sublistB. Pym

1
Subject: Rosetta Code: Sort disjoint sublist
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 18 Aug 2024 05:37 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Rosetta Code: Sort disjoint sublist
Date: Sun, 18 Aug 2024 05:37:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <v9s1af$29f45$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 18 Aug 2024 07:37:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ba36be2ef7e015988cbf9a265c1bd11c";
logging-data="2407557"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nKhpGF6V+yEkA2cSGVbX6"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:KaQgTFD2zKpN+qIiudWk/g54GRo=
View all headers

> Given a list of values and a set of integer indices into that
> value list, the task is to sort the values at the given
> indices, but preserving the values at indices outside the set
> of those to be sorted.
>
> Make your example work with the following list of values and
> set of indices:
> values: [7, 6, 5, 4, 3, 2, 1, 0]
> indices: {6, 1, 7}
>
> Where the correct result would be:
> [7, 0, 5, 4, 3, 2, 1, 6].

newLISP

(set 'values '(7 6 5 4 3 2 1 0))
(set 'positions '(6 1 7))
(set 'sorted-vals (sort (map (fn(n) (values n)) positions)))
(dolist (p (sort positions))
(setf (values p) (pop sorted-vals)))
values

(7 0 5 4 3 2 1 6)

1

rocksolid light 0.9.8
clearnet tor