Deutsch English Français Italiano |
<v9s1af$29f45$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" <Nobody447095@here-nor-there.org> 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= Bytes: 1547 > 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)