Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 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

@ -1,29 +1,29 @@
type PermutationSort
fun isSorted = logic by List a
for int i = 1; i < a.length; ++i
fun isSorted logic by List a
for int i 1; i < a.length; ++i
if a[i - 1] > a[i] do return false end
end
return true
end
fun permute = void by List a, int n, List lists
if n == 1
List b = int[]
for int i = 0; i < a.length; ++i
fun permute void by List a, int n, List lists
if n æ 1
List b int[]
for int i 0; i < a.length; ++i
b.append(a[i])
end
lists.append(b)
return
end
int i = 0
int i 0
while i < n
a.swap(i, n - 1)
permute(a, n - 1, lists)
a.swap(i, n - 1)
i = i + 1
i i + 1
end
end
fun sort = List by List a
List lists = List[]
fun sort List by List a
List lists List[]
permute(a, a.length, lists)
for each List list in lists
if isSorted(list) do return list end
@ -31,7 +31,7 @@ fun sort = List by List a
return a
end
type Main
List a = int[3,2,1,8,9,4,6]
List a int[3,2,1,8,9,4,6]
writeLine("Unsorted: " + a)
a = PermutationSort.sort(a)
a PermutationSort.sort(a)
writeLine(" Sorted: " + a)

View file

@ -0,0 +1,24 @@
local function is_sorted(a)
for i = 1, #a - 1 do
if a[i] > a[i + 1] then return false end
end
return true
end
local a = {170, 45, 75, -90, -802, 24, 2, 66}
-- Recursive permutation generator.
local function recurse(last)
if last <= 1 then return is_sorted(a) end
for i = 1, last do
a[i], a[last] = a[last], a[i]
if recurse(last - 1) then return true end
a[i], a[last] = a[last], a[i]
end
return false
end
print($"Unsorted: \{{a:concat(", ")}}")
local c = #a
if c > 1 and !recurse(c) then error("Sorted permutation not found!") end
print($"Sorted : \{{a:concat(", ")}}")

View file

@ -0,0 +1,40 @@
Function PermutationSort( [Object[]] $indata, $index = 0, $k = 0 )
{
$data = $indata.Clone()
$datal = $data.length - 1
if( $datal -gt 0 ) {
for( $j = $index; $j -lt $datal; $j++ )
{
$sorted = ( PermutationSort $data ( $index + 1 ) $j )[0]
if( -not $sorted )
{
$temp = $data[ $index ]
$data[ $index ] = $data[ $j + 1 ]
$data[ $j + 1 ] = $temp
}
}
if( $index -lt ( $datal - 1 ) )
{
PermutationSort $data ( $index + 1 ) $j
} else {
$sorted = $true
for( $i = 0; ( $i -lt $datal ) -and $sorted; $i++ )
{
$sorted = ( $data[ $i ] -le $data[ $i + 1 ] )
}
$sorted
$data
}
}
}
0..4 | ForEach-Object { $a = $_; 0..4 | Where-Object { -not ( $_ -match "$a" ) } |
ForEach-Object { $b = $_; 0..4 | Where-Object { -not ( $_ -match "$a|$b" ) } |
ForEach-Object { $c = $_; 0..4 | Where-Object { -not ( $_ -match "$a|$b|$c" ) } |
ForEach-Object { $d = $_; 0..4 | Where-Object { -not ( $_ -match "$a|$b|$c|$d" ) } |
ForEach-Object { $e=$_; "$( PermutationSort ( $a, $b, $c, $d, $e ) )" }
}
}
}
}
$l = 8; PermutationSort ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( 0, $l - 1 ) } )