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,31 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Selection_Sort is
type Integer_Array is array (Positive range <>) of Integer;
procedure Sort (A : in out Integer_Array) is
Min : Positive;
Temp : Integer;
begin
for I in A'First..A'Last - 1 loop
Min := I;
for J in I + 1..A'Last loop
if A (Min) > A (J) then
Min := J;
end if;
end loop;
if Min /= I then
Temp := A (I);
A (I) := A (Min);
A (Min) := Temp;
end if;
end loop;
end Sort;
A : Integer_Array := (4, 9, 3, -2, 0, 7, -5, 1, 6, 8);
begin
Sort (A);
for I in A'Range loop
Put (Integer'Image (A (I)) & " ");
end loop;
end Test_Selection_Sort;

View file

@ -0,0 +1,28 @@
PERFORM E-SELECTION VARYING WB-IX-1 FROM 1 BY 1
UNTIL WB-IX-1 = WC-SIZE.
...
E-SELECTION SECTION.
E-000.
SET WC-LOWEST TO WB-IX-1.
ADD 1 WC-LOWEST GIVING WC-START
PERFORM F-PASS VARYING WB-IX-2 FROM WC-START BY 1
UNTIL WB-IX-2 > WC-SIZE.
IF WB-IX-1 NOT = WC-LOWEST
MOVE WB-ENTRY(WC-LOWEST) TO WC-TEMP
MOVE WB-ENTRY(WB-IX-1) TO WB-ENTRY(WC-LOWEST)
MOVE WC-TEMP TO WB-ENTRY(WB-IX-1).
E-999.
EXIT.
F-PASS SECTION.
F-000.
IF WB-ENTRY(WB-IX-2) < WB-ENTRY(WC-LOWEST)
SET WC-LOWEST TO WB-IX-2.
F-999.
EXIT.

View file

@ -0,0 +1,24 @@
function selection_sort(sequence s)
object tmp
integer m
for i = 1 to length(s) do
m = i
for j = i+1 to length(s) do
if compare(s[j],s[m]) < 0 then
m = j
end if
end for
tmp = s[i]
s[i] = s[m]
s[m] = tmp
end for
return s
end function
include misc.e
constant s = {4, 15, "delta", 2, -31, 0, "alfa", 19, "gamma", 2, 13, "beta", 782, 1}
puts(1,"Before: ")
pretty_print(1,s,{2})
puts(1,"\nAfter: ")
pretty_print(1,selection_sort(s),{2})

View file

@ -0,0 +1,21 @@
import Data.List (delete)
-- Sub-Function
selectionSort :: Ord a => [a] -> [a]
selectionSort [] = []
selectionSort xs =
smallest : selectionSort (delete smallest xs)
where smallest = minimum XS
-- Main test driver
main :: IO ()
main = do
let list_of_items = [ 'A', 'S', 'O', 'R', 'I', 'N', 'G', 'E', 'X', 'A', 'M', 'P', 'L', 'E']
putStrLn "Original list:"
print list_of_items
let sorted_list_of_items = selectionSort list_of_items
putStrLn "Sorted list:"
print sorted_list_of_items

View file

@ -0,0 +1,42 @@
-- The main sorting function
selectionSort :: Ord a => [a] -> [a]
selectionSort [] = []
selectionSort unsortedList =
smallestElement : selectionSort remainingElements
where
-- Find the smallest element in the list
smallestElement = findSmallest unsortedList
-- Remove the first occurrence of that smallest element
remainingElements = removeFirst smallestElement unsortedList
-- Function to find the smallest element in a list
-- Uses recursion to compare elements
findSmallest :: Ord a => [a] -> a
findSmallest [singleElement] = singleElement
findSmallest (firstElement:restOfList) =
min firstElement (findSmallest restOfList)
-- Removes the first occurrence of a value from a list
-- This function is pure and returns a new list
removeFirst :: Eq a => a -> [a] -> [a]
removeFirst _ [] = []
removeFirst target (current:rest)
| target == current = rest
| otherwise = current : removeFirst target rest
-- Example usage
main :: IO ()
main = do
let list_of_items = [ 'A', 'S', 'O', 'R', 'I', 'N', 'G', 'E', 'X', 'A', 'M', 'P', 'L', 'E']
putStrLn "Original list:"
print list_of_items
let sorted_list_of_items = selectionSort list_of_items
putStrLn "Sorted list:"
print sorted_list_of_items

View file

@ -0,0 +1,38 @@
class SelectionSort {
@:generic
public static function sort<T>(arr:Array<T>) {
var len = arr.length;
for (index in 0...len) {
var minIndex = index;
for (remainingIndex in (index+1)...len) {
if (Reflect.compare(arr[minIndex], arr[remainingIndex]) > 0)
minIndex = remainingIndex;
}
if (index != minIndex) {
var temp = arr[index];
arr[index] = arr[minIndex];
arr[minIndex] = temp;
}
}
}
}
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);
SelectionSort.sort(integerArray);
Sys.println('Sorted Integers: ' + integerArray);
Sys.println('Unsorted Floats: ' + floatArray);
SelectionSort.sort(floatArray);
Sys.println('Sorted Floats: ' + floatArray);
Sys.println('Unsorted Strings: ' + stringArray);
SelectionSort.sort(stringArray);
Sys.println('Sorted Strings: ' + stringArray);
}
}

View file

@ -0,0 +1,21 @@
local function selection_sort(a)
for i = 1, #a- 1 do
local amin = a[i]
local imin = i
for j = i + 1, #a do
if a[j] < amin then
amin = a[j]
imin = j
end
end
a[i], a[imin] = amin, a[i]
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(", ")}}")
selection_sort(a)
print($"After : \{{a:concat(", ")}}")
print()
end

View file

@ -0,0 +1,20 @@
Function SelectionSort( [Array] $data )
{
$datal=$data.length-1
0..( $datal - 1 ) | ForEach-Object {
$min = $data[ $_ ]
$mini = $_
( $_ + 1 )..$datal | ForEach-Object {
if( $data[ $_ ] -lt $min ) {
$min = $data[ $_ ]
$mini = $_
}
}
$temp = $data[ $_ ]
$data[ $_ ] = $min
$data[ $mini ] = $temp
}
$data
}
$l = 100; SelectionSort( ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( 0, $l - 1 ) } ) )

View file

@ -0,0 +1,197 @@
# riscv assembly raspberry pico2 rp2350
# program selectionsort.s
# connexion putty com3
/*********************************************/
/* CONSTANTES */
/********************************************/
/* for this file see risc-v task include a file */
.include "../../constantesRiscv.inc"
/****************************************************/
/* MACROS */
/****************************************************/
#.include "../ficmacrosriscv.inc" # for debugging only
/*******************************************/
/* INITIALED DATAS */
/*******************************************/
.data
szMessStart: .asciz "Program riscv start.\r\n"
szMessEnd: .asciz "\nProgram end OK.\r\n"
szCariageReturn: .asciz "\r\n"
szMessSortOk: .asciz "Area sorted.\n"
szMessSortNok: .asciz "Area not sorted !!!!!.\n"
szLibSort: .asciz "\nAfter sort\n"
szSpace: .asciz " "
.align 2
tabNumber: .int 5,7,8,3,2,9,11,1,4,10,6
#tabNumber: .int 11,10,9,8,7,6,5,4,3,2,1
.equ NBTABNUMBER1, . - tabNumber
.equ NBTABNUMBER, NBTABNUMBER1 / 4 # compute items number
/*******************************************/
/* UNINITIALED DATA */
/*******************************************/
.bss
.align 2
sConvArea: .skip 24
/********************************...-..--*****/
/* SECTION CODE */
/**********************************************/
.text
.global main
main:
call stdio_init_all # général init
1: # start loop connexion
li a0,0 # raz argument register
call tud_cdc_n_connected # waiting for USB connection
beqz a0,1b # return code = zero ?
la a0,szMessStart # message address
call writeString # display message
la s0,tabNumber # number array address
li s1,0
li s2,NBTABNUMBER
2: # item loop
sh2add t3,s1,s0 # compute item address
lw a0,(t3)
call displayResultD
add s1,s1,1
blt s1,s2,2b
la a0,szCariageReturn
call writeString
mv a0,s0 # number array address
li a1,0 # first item
addi a2,s2,-1 # last item
call selectionSort # sort
mv a0,s0 # number array address
li a1,0 # first item
addi a2,s2,-1 # last item
call isSorted
la a0,szLibSort
call writeString
li s1,0
3: # item loop
sh2add t3,s1,s0 # compute item address
lw a0,(t3)
call displayResultD
add s1,s1,1
blt s1,s2,3b
la a0,szCariageReturn
call writeString
la a0,szMessEnd
call writeString
call getchar
100: # final loop
j 100b
/**********************************************/
/* display Result décimal */
/**********************************************/
/* a0 value */
.equ LGZONECONV, 20
displayResultD:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp)
la a1,sConvArea # conversion result address
call conversion10 # binary conversion
la a0,sConvArea # message address
call writeString # display message
la a0,szSpace
call writeString
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/**********************************************/
/* sort control */
/**********************************************/
/* a0 area address */
/* a1 first element */
/* a2 last element */
.equ LGZONECONV, 20
isSorted:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp)
mv t0,a1
sh2add t1,t0,a0
lw t2,(t1) # load first element
1:
addi t0,t0,1
ble t0,a2,2f # end indice ?
la a0,szMessSortOk
call writeString
li a0,1 # yes -> area is sorted
j 100f
2:
sh2add t1,t0,a0
lw t3,(t1) # load next element
bge t3,t2,3f # >= ?
la a0,szMessSortNok
call writeString
li a0,0 # no -> area is not sorted
j 100f
3:
mv t2,t3
j 1b
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/******************************************************************/
/* selection sort */
/******************************************************************/
/* a0 contains array address */
/* a1 contains the first element */
/* a2 contains the last element */
selectionSort:
addi sp, sp, -12 # reserve stack
sw ra, 0(sp) # save registers
sw s0, 4(sp)
sw s1, 8(sp)
mv t1,a1
1: # start loop 1
mv t0,t1 # start index
addi t4,t0,1
2: # start loop 2
sh2add t6,t0,a0
lw s0,(t6)
sh2add s1,t4,a0
lw t2,(s1)
bge t2,s0,3f
mv t0,t4
3:
addi t4,t4,1
ble t4,a2,2b
beq t0,t1,4f
sh2add t6,t0,a0
lw s0,(t6)
sh2add s1,t1,a0
lw t2,(s1)
sw t2,(t6) # swap value
sw s0,(s1)
4:
addi t1,t1,1
ble t1,a2,1b # end ? no -> loop 1
100:
lw ra, 0(sp)
lw s0, 4(sp)
lw s1, 8(sp)
addi sp, sp, 12
ret
/************************************/
/* file include Fonctions */
/***********************************/
/* for this file see risc-v task include a file */
.include "../../includeFunctions.s"

View file

@ -0,0 +1,19 @@
Function Selection_Sort(s)
arr = Split(s,",")
For i = 0 To UBound(arr)
For j = i To UBound(arr)
temp = arr(i)
If arr(j) < arr(i) Then
arr(i) = arr(j)
arr(j) = temp
End If
Next
Next
Selection_Sort = (Join(arr,","))
End Function
WScript.StdOut.Write "Pre-Sort" & vbTab & "Sorted"
WScript.StdOut.WriteLine
WScript.StdOut.Write "3,2,5,4,1" & vbTab & Selection_Sort("3,2,5,4,1")
WScript.StdOut.WriteLine
WScript.StdOut.Write "c,e,b,a,d" & vbTab & Selection_Sort("c,e,b,a,d")