Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,57 +0,0 @@
|
|||
with Ada.Text_IO, GNAT.Bubble_Sort;
|
||||
use Ada.Text_IO;
|
||||
|
||||
procedure DisjointSort is
|
||||
|
||||
package Int_Io is new Integer_IO (Integer);
|
||||
|
||||
subtype Index_Range is Natural range 1 .. 8;
|
||||
Input_Array : array (Index_Range) of Integer := (7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
subtype Subindex_Range is Natural range 1 .. 3;
|
||||
type Sub_Arrays is array (Subindex_Range) of Integer;
|
||||
|
||||
Sub_Index : Sub_Arrays := (7, 2, 8);
|
||||
Sub_Array : Sub_Arrays;
|
||||
|
||||
-- reuse of the somehow generic GNAT.Bubble_Sort (for Ada05)
|
||||
|
||||
procedure Sort (Work_Array : in out Sub_Arrays) is
|
||||
procedure Exchange (Op1, Op2 : Natural) is
|
||||
Temp : Integer;
|
||||
begin
|
||||
Temp := Work_Array (Op1);
|
||||
Work_Array (Op1) := Work_Array (Op2);
|
||||
Work_Array (Op2) := Temp;
|
||||
end Exchange;
|
||||
|
||||
function Lt (Op1, Op2 : Natural) return Boolean is
|
||||
begin
|
||||
return (Work_Array (Op1) < Work_Array (Op2));
|
||||
end Lt;
|
||||
begin
|
||||
GNAT.Bubble_Sort.Sort
|
||||
(N => Subindex_Range'Last,
|
||||
Xchg => Exchange'Unrestricted_Access,
|
||||
Lt => Lt'Unrestricted_Access);
|
||||
end Sort;
|
||||
|
||||
begin
|
||||
-- as the positions are not ordered, first sort the positions
|
||||
Sort (Sub_Index);
|
||||
-- extract the values to be sorted
|
||||
for I in Subindex_Range loop
|
||||
Sub_Array (I) := Input_Array (Sub_Index (I));
|
||||
end loop;
|
||||
Sort (Sub_Array);
|
||||
-- put the sorted values at the right place
|
||||
for I in Subindex_Range loop
|
||||
Input_Array (Sub_Index (I)) := Sub_Array (I);
|
||||
end loop;
|
||||
|
||||
for I in Index_Range loop
|
||||
Int_Io.Put (Input_Array (I), Width => 2);
|
||||
end loop;
|
||||
New_Line;
|
||||
|
||||
end DisjointSort;
|
||||
|
|
@ -3,7 +3,7 @@ sortDisjoint: function [data, indices][
|
|||
inds: new indices
|
||||
sort 'inds
|
||||
|
||||
vals: new []
|
||||
vals: []
|
||||
loop inds 'i -> 'vals ++ result\[i]
|
||||
sort 'vals
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import system'culture;
|
|||
|
||||
extension op
|
||||
{
|
||||
sortSublist(indices)
|
||||
sortSublist(int[] indices)
|
||||
{
|
||||
var subList := indices.orderBy::(x => x)
|
||||
.zipBy(indices.selectBy::(i => self[i])
|
||||
|
|
@ -21,9 +21,9 @@ extension op
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var list := new int[]{ 7, 6, 5, 4, 3, 2, 1, 0 };
|
||||
auto list := new int[]{ 7, 6, 5, 4, 3, 2, 1, 0 };
|
||||
|
||||
console.printLine(list.sortSublist(new int[]{6, 1, 7}).asEnumerable())
|
||||
Console.printLine(list.sortSublist(new int[]{6, 1, 7}).asEnumerable())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
include sort.e
|
||||
|
||||
function uniq(sequence s)
|
||||
sequence out
|
||||
out = s[1..1]
|
||||
for i = 2 to length(s) do
|
||||
if not find(s[i], out) then
|
||||
out = append(out, s[i])
|
||||
end if
|
||||
end for
|
||||
return out
|
||||
end function
|
||||
|
||||
function disjointSort(sequence s, sequence idx)
|
||||
sequence values
|
||||
idx = uniq(sort(idx))
|
||||
values = repeat(0, length(idx))
|
||||
for i = 1 to length(idx) do
|
||||
values[i] = s[idx[i]]
|
||||
end for
|
||||
values = sort(values)
|
||||
for i = 1 to length(idx) do
|
||||
s[idx[i]] = values[i]
|
||||
end for
|
||||
return s
|
||||
end function
|
||||
|
||||
constant data = {7, 6, 5, 4, 3, 2, 1, 0}
|
||||
constant indexes = {7, 2, 8}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">disjoint_sort</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">idx</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">idx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">copies</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">l</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">copies</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]]</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #000000;">copies</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">copies</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">l</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">copies</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #0000FF;">?</span><span style="color: #000000;">disjoint_sort</span><span style="color: #0000FF;">({</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">})</span>
|
||||
<!--
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">disjoint_sort</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">idx</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">idx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">reinstate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">extract</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">)))</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #0000FF;">?</span><span style="color: #000000;">disjoint_sort</span><span style="color: #0000FF;">({</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">})</span>
|
||||
<!--
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
function sublistsort($values, $indices) {
|
||||
$indices = $indices | sort
|
||||
$sub, $i = ($values[$indices] | sort), 0
|
||||
$indices | foreach { $values[$_] = $sub[$i++] }
|
||||
$values
|
||||
}
|
||||
$values = 7, 6, 5, 4, 3, 2, 1, 0
|
||||
$indices = 6, 1, 7
|
||||
"$(sublistsort $values $indices)"
|
||||
|
|
@ -1,31 +1,45 @@
|
|||
/*REXX program uses a disjointed sublist to sort a random list of values. */
|
||||
parse arg old ',' idx /*obtain the optional lists from the CL*/
|
||||
if old='' then old= 7 6 5 4 3 2 1 0 /*Not specified: Then use the default.*/
|
||||
if idx='' then idx= 7 2 8 /* " " " " " " */
|
||||
say ' list of indices:' idx; say /* [↑] is for one─based lists. */
|
||||
say ' unsorted list:' old /*display the old list of numbers. */
|
||||
say ' sorted list:' disjoint_sort(old,idx) /*sort 1st list using 2nd list indices.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
disjoint_sort: procedure; parse arg x,ix; y=; z=; p= 0
|
||||
ix= sortL(ix) /*ensure the index list is sorted*/
|
||||
do i=1 for words(ix) /*extract indexed values from X.*/
|
||||
z= z word(x, word(ix, i) ) /*pick the correct value from X.*/
|
||||
end /*j*/
|
||||
z= sortL(z) /*sort extracted (indexed) values*/
|
||||
do m=1 for words(x) /*re─build (re-populate) X list.*/
|
||||
if wordpos(m, ix)==0 then y=y word(x,m) /*is the same or new?*/
|
||||
else do; p= p + 1; y= y word(z, p)
|
||||
end
|
||||
end /*m*/
|
||||
return strip(y)
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
sortL: procedure; parse arg L; n= words(L); do j=1 for n; @.j= word(L,j)
|
||||
end /*j*/
|
||||
do k=1 for n-1 /*sort a list using a slow method*/
|
||||
do m=k+1 to n; if @.m<@.k then parse value @.k @.m with @.m @.k
|
||||
end /*m*/
|
||||
end /*k*/ /* [↑] use PARSE for swapping.*/
|
||||
$= @.1; do j=2 to n; $= $ @.j
|
||||
end /*j*/
|
||||
return $
|
||||
-- 21 Jan 2026
|
||||
include Setting
|
||||
|
||||
say 'SORT DISJOINT SUBLIST'
|
||||
say version
|
||||
say
|
||||
call Prepare
|
||||
say 'INPUT'
|
||||
call Stemshow 'vals. inds.idx.',3
|
||||
-- Order by index, sync value
|
||||
call Stemsort 'inds.idx.','inds.val.'
|
||||
-- Order by value, don't sync index
|
||||
call Stemsort 'inds.val.'
|
||||
-- Put ordered values back in list
|
||||
call Update
|
||||
say 'OUTPUT'
|
||||
call Stemshow 'vals.',3
|
||||
exit
|
||||
|
||||
Prepare:
|
||||
procedure expose vals. inds.
|
||||
-- Save values
|
||||
values=7 6 5 4 3 2 1 0; n=Words(values)
|
||||
do i=1 to n
|
||||
vals.i=Word(values,i)
|
||||
end
|
||||
vals.0=n
|
||||
-- Save 1-based indices and their values
|
||||
indices=7 2 8; n=Words(indices)
|
||||
do i=1 to n
|
||||
index=Word(indices,i); inds.val.i=vals.index; inds.idx.i=index
|
||||
end
|
||||
inds.0=n
|
||||
return
|
||||
|
||||
Update:
|
||||
procedure expose vals. inds.
|
||||
-- Restore sorted values
|
||||
do i=1 to inds.0
|
||||
index=inds.idx.i; vals.index=inds.val.i
|
||||
end
|
||||
return
|
||||
|
||||
-- Stemshow Stemsort
|
||||
include Math
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue