Sort disjoint sublist: Difference between revisions

m
(Added Quackery.)
m (→‎{{header|Wren}}: Minor tidy)
 
(5 intermediate revisions by 4 users not shown)
Line 1,730:
[7 0 5 4 3 2 1 6]
Elapsed Time: 0.626 ms.</pre>
 
=={{header|QuackeryEasyLang}}==
<syntaxhighlight lang="Quackery">
<pre>val[] = [ 7 06 5 4 3 2 1 60 ]</pre>
ind[] = [ 7 2 8 ]
#
for i = 1 to len ind[] - 1
for j = i + 1 to len ind[]
if ind[j] < ind[i]
swap ind[j] ind[i]
.
.
.
for i = 1 to len ind[] - 1
for j = i + 1 to len ind[]
if val[ind[j]] < val[ind[i]]
swap val[ind[j]] val[ind[i]]
.
.
.
print val[]
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 1,752 ⟶ 1,774:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
import system'routines;
Line 1,761 ⟶ 1,783:
sortSublist(indices)
{
var subList := indices.orderBy::(x => x)
.zipBy(indices.selectBy::(i => self[i])
.orderBy::(x => x), (index,val => new{ Index = index; Value = val; }))
.toArray();
var list := self.clone();
subList.forEach::(r)
{
list[r.Index] := r.Value
Line 2,649 ⟶ 2,671:
{{out}}
<pre>{ 7, 0, 5, 4, 3, 2, 1, 6 }</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
sortDisjointSublist = function(arr, indexes)
indexes.sort
newArr = arr[:]
sublist = []
for i in indexes
sublist.push(arr[i])
end for
sublist.sort
for i in range(0, indexes.len - 1)
arrIx = indexes[i]
newArr[arrIx] = sublist[i]
end for
return newArr
end function
 
print sortDisjointSublist([7,6,5,4,3,2,1,0], [6,1,7])
</syntaxhighlight>
{{out}}
<pre>
[7, 0, 5, 4, 3, 2, 1, 6]
</pre>
 
=={{header|NetRexx}}==
Line 3,339 ⟶ 3,385:
Output:
<pre> 7 0 5 4 3 2 1 6</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery">
[ sort tuck [] unrot
witheach
[ dip dup peek
rot join swap ]
swap sort
dip swap witheach
[ over i^ peek
dip rot poke
swap ]
drop ] is sortdisjointsublist ( [ [ --> [ )
 
' [ 7 6 5 4 3 2 1 0 ] ' [ 6 1 7 ] sortdisjointsublist echo</syntaxhighlight>
 
{{out}}
 
<pre>[ 7 0 5 4 3 2 1 6 ]</pre>
 
=={{header|Racket}}==
Line 3,728 ⟶ 3,754:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "./sort" for Sort
 
// sorts values in place, leaves indices unsorted
9,479

edits