Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,39 @@
-- Permutation sort
-- J. Carter 2024 Jun
-- Uses the PragmAda Reusable Components (https://github.com/jrcarter/PragmARC)
with Ada.Text_IO;
with PragmARC.Permutations;
procedure Slow_Sort is
package Char_Perms is new PragmARC.Permutations (Element => Character);
procedure Put (Item : in Char_Perms.Sequence);
-- Outputs all the Characters in Item to standard output, followed by a line terminator
procedure Process (Seq : in Char_Perms.Sequence; Stop : in out Boolean);
-- If Seq is sorted, outputs it and sets Stop to True
procedure Put (Item : in Char_Perms.Sequence) is
-- Empty
begin -- Put
All_Chars : for C of Item loop
Ada.Text_IO.Put (Item => C);
end loop All_Chars;
Ada.Text_IO.New_Line;
end Put;
procedure Process (Seq : in Char_Perms.Sequence; Stop : in out Boolean) is
-- Empty
begin -- Process
if (for all J in 1 .. Seq'Last - 1 => Seq (J) <= Seq (J + 1) ) then -- Sorted
Put (Item => Seq);
Stop := True;
end if;
end Process;
Test : constant Char_Perms.Sequence := "kjihgfedcba";
begin -- Slow_Sort
Char_Perms.Generate (Initial => Test, Process => Process'Access);
end Slow_Sort;

View file

@ -0,0 +1,49 @@
global perm[] .
proc nextperm . a[] .
n = len perm[]
k = n - 1
while k >= 1 and perm[k + 1] <= perm[k]
k -= 1
.
if k = 0
a[] = [ ]
return
.
l = n
while perm[l] <= perm[k]
l -= 1
.
swap perm[l] perm[k]
swap a[l] a[k]
k += 1
while k < n
swap perm[k] perm[n]
swap a[k] a[n]
k += 1
n -= 1
.
.
proc perminit . a[] .
for i to len a[]
perm[] &= i
.
.
proc permsort . a[] .
perminit a[]
repeat
for i = 2 to len a[]
if a[i - 1] > a[i]
break 1
.
.
until i > len a[]
nextperm a[]
if len a[] = 0
print "error"
break 1
.
.
.
arr[] = [ 7 6 5 9 8 4 3 1 2 0 ]
permsort arr[]
print arr[]