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,49 @@
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Numerics; use Ada.Numerics;
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Counting_Sort is
type Data is array (Integer range <>) of Natural;
procedure Sort(Item : in out Data) is
minValue, maxValue: Natural;
begin
minValue := Item(Item'First); maxValue := Item(Item'First);
for I in Item'Range loop
if Item(I) < minValue then minValue := Item(I); end if;
if Item(I) > maxValue then maxValue := Item(I); end if;
end loop;
declare
Count : Data(minValue .. maxValue);
itemPos : Integer range Item'First - 1 .. Item'Last;
begin
for I in Count'Range loop
Count(I) := 0;
end loop;
for I in Item'Range loop
Count(Item(I)) := Count(Item(I)) + 1;
end loop;
itemPos := 0;
for I in Count'Range loop
for J in 1..Count(I) loop
itemPos := itemPos + 1;
Item(itemPos) := I;
end loop;
end loop;
end;
end Sort;
Stuff : Data(1..30);
Seed : Generator;
begin
Put("Before: ");
for I in Stuff'Range loop
Stuff(I) := Integer( Float'Truncation( Random( seed ) * 100.0 ) );
Put(Natural'Image(Stuff(I)));
end loop;
New_Line;
Sort(Stuff);
Put("After : ");
for I in Stuff'range loop
Put(Natural'Image(Stuff(I)));
end loop;
New_Line;
end Counting_Sort;

View file

@ -10,8 +10,6 @@ proc countsort min max &d[] .
.
.
.
for i = 1 to 100
d[] &= random 1000
.
for i = 1 to 50 : d[] &= random 0 999
countsort 1 1000 d[]
print d[]

View file

@ -0,0 +1,33 @@
class CountingSort {
public static function sort(arr:Array<Int>) {
var min = arr[0], max = arr[0];
for (i in 1...arr.length) {
if (arr[i] < min)
min = arr[i];
else if (arr[i] > max)
max = arr[i];
}
var range = max - min + 1;
var count = new Array<Int>();
count.resize(range * arr.length);
for (i in 0...range) count[i] = 0;
for (i in 0...arr.length) count[arr[i] - min]++;
var z = 0;
for (i in min...(max + 1)) {
for (j in 0...count[i - min])
arr[z++] = i;
}
}
}
class Main {
static function main() {
var integerArray = [1, 10, 2, 5, -1, 5, -19, 4, 23, 0];
Sys.println('Unsorted Integers: ' + integerArray);
CountingSort.sort(integerArray);
Sys.println('Sorted Integers: ' + integerArray);
}
}

View file

@ -0,0 +1,19 @@
counting_sort(list) := block(
low: lmin(list), high: lmax(list),
for i in list do(count[i]: 0),
for i in list do(count[i]: count[i]+1),
z: 1,
for i from low thru high do(
if numberp(count[i]) then while count[i]>0 do(
list[z]: i,
z: z+1,
count[i]: count[i]-1
)
),
kill(count),
list
)$
test_list: makelist(random(10), 10);
counting_sort(test_list);

View file

@ -0,0 +1,19 @@
require "table2"
local function counting_sort(a, min, max)
local count = table.rep(max - min + 1, 0)
for a as n do count[n - min + 1] += 1 end
local z = 1
for i = min, max do
while count[i - min + 1] > 0 do
a[z] = i
z += 1
count[i - min + 1] -= 1
end
end
end
local a = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}
print($"Unsorted: \{{a:concat(", ")}")
counting_sort(a, a:min(), a:max())
print($"Sorted: \{{a:concat(", ")}")

View file

@ -0,0 +1,21 @@
function countingSort($array) {
$minmax = $array | Measure-Object -Minimum -Maximum
$min, $max = $minmax.Minimum, $minmax.Maximum
$count = @(0) * ($max - $min + 1)
foreach ($number in $array) {
$count[$number - $min] = $count[$number - $min] + 1
}
$z = 0
foreach ($i in $min..$max) {
while (0 -lt $count[$i - $min]) {
$array[$z] = $i
$z = $z+1
$count[$i - $min] = $count[$i - $min] - 1
}
}
$array
}
$array = foreach ($i in 1..50) {Get-Random -Minimum 0 -Maximum 26}
"$array"
"$(countingSort $array)"

View file

@ -0,0 +1,42 @@
function findMax( a )
dim num
dim max
max = 0
for each num in a
if num > max then max = num
next
findMax = max
end function
function findMin( a )
dim num
dim min
min = 0
for each num in a
if num < min then min = num
next
findMin = min
end function
'the function returns the sorted array, but the fact is that VBScript passes the array by reference anyway
function countingSort( a )
dim count()
dim min, max
min = findMin(a)
max = findMax(a)
redim count( max - min + 1 )
dim i
dim z
for i = 0 to ubound( a )
count( a(i) - min ) = count( a( i ) - min ) + 1
next
z = 0
for i = min to max
while count( i - min) > 0
a(z) = i
z = z + 1
count( i - min ) = count( i - min ) - 1
wend
next
countingSort = a
end function

View file

@ -0,0 +1,5 @@
dim a
a = array(300, 1, -2, 3, -4, 5, -6, 7, -8, 100, 11 )
wscript.echo join( a, ", " )
countingSort a
wscript.echo join( a, ", " )