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,47 @@
with Ada.Text_IO;
procedure Comb_Sort is
generic
type Element_Type is private;
type Index_Type is range <>;
type Array_Type is array (Index_Type range <>) of Element_Type;
with function ">" (Left, Right : Element_Type) return Boolean is <>;
with function "+" (Left : Index_Type; Right : Natural) return Index_Type is <>;
with function "-" (Left : Index_Type; Right : Natural) return Index_Type is <>;
procedure Comb_Sort (Data: in out Array_Type);
procedure Comb_Sort (Data: in out Array_Type) is
procedure Swap (Left, Right : in Index_Type) is
Temp : Element_Type := Data(Left);
begin
Data(Left) := Data(Right);
Data(Right) := Temp;
end Swap;
Gap : Natural := Data'Length;
Swap_Occured : Boolean;
begin
loop
Gap := Natural (Float(Gap) / 1.25 - 0.5);
if Gap < 1 then
Gap := 1;
end if;
Swap_Occured := False;
for I in Data'First .. Data'Last - Gap loop
if Data (I) > Data (I+Gap) then
Swap (I, I+Gap);
Swap_Occured := True;
end if;
end loop;
exit when Gap = 1 and not Swap_Occured;
end loop;
end Comb_Sort;
type Integer_Array is array (Positive range <>) of Integer;
procedure Int_Comb_Sort is new Comb_Sort (Integer, Positive, Integer_Array);
Test_Array : Integer_Array := (1, 3, 256, 0, 3, 4, -1);
begin
Int_Comb_Sort (Test_Array);
for I in Test_Array'Range loop
Ada.Text_IO.Put (Integer'Image (Test_Array (I)));
end loop;
Ada.Text_IO.New_Line;
end Comb_Sort;

View file

@ -0,0 +1,41 @@
C-PROCESS SECTION.
C-000.
DISPLAY "SORT STARTING".
MOVE WC-SIZE TO WC-GAP.
PERFORM E-COMB UNTIL WC-GAP = 1 AND FINISHED.
DISPLAY "SORT FINISHED".
C-999.
EXIT.
E-COMB SECTION.
E-000.
IF WC-GAP > 1
DIVIDE WC-GAP BY 1.3 GIVING WC-GAP
IF WC-GAP = 9 OR 10
MOVE 11 TO WC-GAP.
MOVE 1 TO WC-SUB-1.
MOVE "Y" TO WF-FINISHED.
PERFORM F-SCAN UNTIL WC-SUB-1 + WC-GAP > WC-SIZE.
E-999.
EXIT.
F-SCAN SECTION.
F-000.
ADD WC-SUB-1 WC-GAP GIVING WC-SUB-2.
IF WB-ENTRY(WC-SUB-1) > WB-ENTRY(WC-SUB-2)
MOVE WB-ENTRY(WC-SUB-1) TO WC-TEMP
MOVE WB-ENTRY(WC-SUB-2) TO WB-ENTRY(WC-SUB-1)
MOVE WC-TEMP TO WB-ENTRY(WC-SUB-2)
MOVE "N" TO WF-FINISHED.
ADD 1 TO WC-SUB-1.
F-999.
EXIT.

View file

@ -0,0 +1,43 @@
class CombSort {
@:generic
public static function sort<T>(arr:Array<T>) {
var gap:Float = arr.length;
var swaps = true;
while (gap > 1 || swaps) {
gap /= 1.247330950103979;
if (gap < 1) gap = 1.0;
var i = 0;
swaps = false;
while (i + gap < arr.length) {
var igap = i + Std.int(gap);
if (Reflect.compare(arr[i], arr[igap]) > 0) {
var temp = arr[i];
arr[i] = arr[igap];
arr[igap] = temp;
swaps = true;
}
i++;
}
}
}
}
class Main {
static function main() {
var integerArray = [1, 10, 2, 5, -1, 5, -19, 4, 23, 0];
var floatArray = [1.0, -3.2, 5.2, 10.8, -5.7, 7.3,
3.5, 0.0, -4.1, -9.5];
var stringArray = ['We', 'hold', 'these', 'truths', 'to',
'be', 'self-evident', 'that', 'all',
'men', 'are', 'created', 'equal'];
Sys.println('Unsorted Integers: ' + integerArray);
CombSort.sort(integerArray);
Sys.println('Sorted Integers: ' + integerArray);
Sys.println('Unsorted Floats: ' + floatArray);
CombSort.sort(floatArray);
Sys.println('Sorted Floats: ' + floatArray);
Sys.println('Unsorted Strings: ' + stringArray);
CombSort.sort(stringArray);
Sys.println('Sorted Strings: ' + stringArray);
}
}

View file

@ -0,0 +1,26 @@
local function comb_sort(a)
local gap = #a
while true do
gap //= 1.25
if gap < 1 then gap = 1 end
local i = 1
local swaps = false
while true do
if a[i] > a[i + gap] then
a[i], a[i + gap] = a[i + gap], a[i]
swaps = true
end
i += 1
if i + gap > #a then break end
end
if gap == 1 and !swaps then return end
end
end
local array = { {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}, {7, 5, 2, 6, 1, 4, 2, 6, 3} }
for array as a do
print($"Before: \{{a:concat(", ")}}")
comb_sort(a)
print($"After : \{{a:concat(", ")}}")
print()
end

View file

@ -0,0 +1,31 @@
function CombSort ($a) {
$l = $a.Length
$gap = 11
while( $gap -lt $l )
{
$gap = [Math]::Floor( $gap*1.3 )
}
if( $l -gt 1 )
{
$hasChanged = $true
:outer while ($hasChanged -or ( $gap -gt 1 ) ) {
$count = 0
$hasChanged = $false
if( $gap -gt 1 ) {
$gap = [Math]::Floor( $gap/1.3 )
} else {
$l--
}
for ($i = 0; $i -lt ( $l - $gap ); $i++) {
if ($a[$i] -gt $a[$i+$gap]) {
$a[$i], $a[$i+$gap] = $a[$i+$gap], $a[$i]
$hasChanged = $true
$count++
}
}
}
}
$a
}
$l = 100; CombSort ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( -( $l - 1 ), $l - 1 ) } )