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,71 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_Array_Sort
(Index_Type => Natural, Element_Type => Long_Float,
Array_Type => Data_Array);
function Median (X : Data_Array) return Long_Float with
Pre => X'Length > 0;
function Median (X : Data_Array) return Long_Float is
M : constant Natural := X'First + X'Last / 2;
begin
if X'Length rem 2 = 1 then
return X (M);
else
return (X (M - 1) + X (M)) / 2.0;
end if;
end Median;
procedure fivenum (X : Data_Array; Result : out Five_Num_Type) is
Temp : Data_Array := X;
m : Natural := X'Length / 2;
Lower_end : Natural := (if X'Length rem 2 = 0 then m - 1 else m);
begin
Sort (Temp);
Result (0) := Temp (Temp'First);
Result (2) := Median (Temp);
Result (4) := Temp (Temp'Last);
Result (1) := Median (Temp (1 .. Lower_end));
Result (3) := Median (Temp (m .. Temp'Last));
end fivenum;
procedure print (Result : Five_Num_Type; Aft : Natural) is
begin
Put ("[");
for I in Result'Range loop
Put (Item => Result (I), Fore => 1, Aft => Aft, Exp => 0);
if I < Result'Last then
Put (", ");
else
Put_Line ("]");
end if;
end loop;
New_Line;
end print;
X1 : Data_Array :=
(15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0, 39.0, 47.0, 43.0);
X2 : Data_Array := (36.0, 40.0, 7.0, 39.0, 41.0, 15.0);
X3 : Data_Array :=
(0.140_828_34, 0.097_487_90, 1.731_315_07, 0.876_360_09, -1.950_595_94,
0.734_385_55, -0.030_357_26, 1.466_759_70, -0.746_213_49, -0.725_887_72,
0.639_051_60, 0.615_015_27, -0.989_837_80, -1.004_478_74, -0.627_594_69,
0.662_061_63, 1.043_120_09, -0.103_053_85, 0.757_756_34, 0.325_665_78);
Result : Five_Num_Type;
begin
fivenum (X1, Result);
print (Result, 1);
fivenum (X2, Result);
print (Result, 1);
fivenum (X3, Result);
print (Result, 9);
end Main;

View file

@ -0,0 +1,80 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
type fivenum_index is (minimum, lower_hinge, median, upper_hinge, maximum);
type Five_Num_Type is array (fivenum_index) of Long_Float;
procedure Sort is new Ada.Containers.Generic_Array_Sort
(Index_Type => Natural, Element_Type => Long_Float,
Array_Type => Data_Array);
function Median (X : Data_Array) return Long_Float with
Pre => X'Length > 0;
function Median (X : Data_Array) return Long_Float is
M : constant Natural := X'First + X'Last / 2;
begin
if X'Length rem 2 = 1 then
return X (M);
else
return (X (M - 1) + X (M)) / 2.0;
end if;
end Median;
procedure fivenum (X : Data_Array; Result : out Five_Num_Type) is
Temp : Data_Array := X;
m : Natural := X'Length / 2;
Lower_end : Natural := (if X'Length rem 2 = 0 then m - 1 else m);
begin
Sort (Temp);
Result (minimum) := Temp (Temp'First);
Result (lower_hinge) := Median (Temp (0 .. Lower_end));
Result (median) := Median (Temp);
Result (upper_hinge) := Median (Temp (m .. Temp'Last));
Result (maximum) := Temp (Temp'Last);
end fivenum;
procedure print (Result : Five_Num_Type) is
package five_io is new Enumeration_IO (fivenum_index);
use five_io;
begin
for I in fivenum_index loop
Put(" ");
Put (Item => I, Width => 12);
end loop;
New_Line;
Put ("[");
for I in Result'Range loop
Put (Item => Result (I), Fore => 3, Aft => 9, Exp => 0);
if I < Result'Last then
Put (", ");
else
Put_Line ("]");
end if;
end loop;
New_Line;
end print;
X1 : Data_Array :=
(15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0, 39.0, 47.0, 43.0);
X2 : Data_Array := (36.0, 40.0, 7.0, 39.0, 41.0, 15.0);
X3 : Data_Array :=
(0.140_828_34, 0.097_487_90, 1.731_315_07, 0.876_360_09, -1.950_595_94,
0.734_385_55, -0.030_357_26, 1.466_759_70, -0.746_213_49, -0.725_887_72,
0.639_051_60, 0.615_015_27, -0.989_837_80, -1.004_478_74, -0.627_594_69,
0.662_061_63, 1.043_120_09, -0.103_053_85, 0.757_756_34, 0.325_665_78);
Result : Five_Num_Type;
begin
fivenum (X1, Result);
print (Result);
fivenum (X2, Result);
print (Result);
fivenum (X3, Result);
print (Result);
end Main;

View file

@ -1,30 +1,28 @@
type Fivenum
int ILLEGAL_ARGUMENT = 0
fun median = real by List x, int start, int endInclusive
int size = endInclusive - start + 1
if size <= 0 do error(ILLEGAL_ARGUMENT, "Array slice cannot be empty") end
int m = start + size / 2
return when(size % 2 == 1, x[m], (x[m - 1] + x[m]) / 2.0)
int ILLEGAL_ARGUMENT 0
fun median real by List x, int start, int endInclusive
int size endInclusive - start + 1
if size 0 do error(ILLEGAL_ARGUMENT, "Array slice cannot be empty") end
int m start + size / 2
return when(size % 2 æ 1, x[m], (x[m - 1] + x[m]) / 2.0)
end
fun fivenum = List by List x
List result = real[].with(5)
fun fivenum List by List x
List result real[].with(5)
x.order()
result[0] = x[0]
result[2] = median(x, 0, x.length - 1)
result[4] = x[x.length - 1]
int m = x.length / 2
int lowerEnd = when(x.length % 2 == 1, m, m - 1)
result[1] = median(x, 0, lowerEnd)
result[3] = median(x, m, x.length - 1)
result[0] x[0]
result[2] median(x, 0, x.length - 1)
result[4] x[x.length - 1]
int m x.length / 2
int lowerEnd ← when(x.length % 2 æ 1, m, m - 1)
result[1] median(x, 0, lowerEnd)
result[3] median(x, m, x.length - 1)
return result
end
List lists = List[
List lists List[
real[15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0, 39.0, 47.0, 43.0],
real[36.0, 40.0, 7.0, 39.0, 41.0, 15.0],
real[ 0.14082834, 0.09748790, 1.73131507, 0.87636009, -1.95059594, 0.73438555,
-0.03035726, 1.46675970, -0.74621349, -0.72588772, 0.63905160,
0.61501527, -0.98983780, -1.00447874, -0.62759469, 0.66206163,
1.04312009, -0.10305385, 0.75775634, 0.32566578] ]
for each List list in lists
writeLine(text!fivenum(list))
end
lists.list(<List list|writeLine(text!fivenum(list)))

View file

@ -0,0 +1,144 @@
! Fivenum
! tested with Intel ifx (IFX) 2025.2.1 20250806 on Kubuntu 25.10
! GNU Fortran (Ubuntu 15.2.0-4ubuntu4) 15.2.0 on Kubuntu 25.10
! VSI Fortran x86-64 V8.6-001 on OpenVMS x86_64 V9.2-3
! Uses non-standard intrinsic isnan(), available as extension on all 3 mentioned compilers
! U.B., January 2026
!=========================================================================================
program p_fivenum
implicit none
integer, parameter :: dp=8
real (kind=dp), dimension(11) :: x1 = [15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0, 39.0, 47.0, 43.0]
real (kind=dp), dimension(6) :: x2 = [36.0, 40.0, 7.0, 39.0, 41.0, 15.0]
! With so many valid digits, its better to specify the constants as real (kind=dp) to avoid precision loss
real (kind=dp), dimension(20) :: x3 = [0.14082834_dp, 0.09748790_dp, 1.73131507_dp, 0.87636009_dp, -1.95059594_dp, &
0.73438555_dp, -0.03035726_dp, 1.46675970_dp, -0.74621349_dp, -0.72588772_dp, &
0.63905160_dp, 0.61501527_dp, -0.98983780_dp, -1.00447874_dp, -0.62759469_dp, &
0.66206163_dp, 1.04312009_dp, -0.10305385_dp, 0.75775634_dp, 0.32566578_dp]
real (kind=dp), dimension(5) :: result
if (fivenum (x1,result,size(x1))) call show (result, '(5 (X,F4.1))')
if (fivenum (x2,result,size(x2))) call show (result, '(5 (X,F4.1))')
if (fivenum (x3,result,size(x3))) call show (result, '(5 (X,F11.8))')
contains
function fivenum (x,res,n) result(OK)
integer,intent(in) :: n ! size of the...
real (kind=dp), dimension(n), intent (inout) :: x ! value array
real (kind=dp), dimension(5), intent(out) :: res ! the 5-number result
logical :: OK ! this will signal success or failure
integer :: ii ! loop index
integer:: rmid, lmid ! index to the 2 central elements of the array
! ... these values are different if n is even
!-- Check for invalid input: nan is not a number to calculate with
OK = .true. ! Assume success
do ii=1,n
if (isnan (x(ii))) then ! isNan() is non-standard extension in IFX and also in gfortran
OK = .false. ! signal fault
print *, 'Unable to deal with arrays containing NaN'
return
endif
end do
! value array must be sorted ascending
call quicksort_real (x, 1, n)
! Divide array into 4 sections
rmid = 1 + n/2 ! right middle
if (mod (n, 2) .eq. 1) then ! odd array size?
lmid = rmid ! left and right half end/begin on the same element
else
lmid = rmid - 1 ! left half ends at lmid, right half begins at rmid.
end if
! fill result values as defined
res(1) = x(1) ! min value
res(2) = median (x, 1, lmid) ! lower hinge
res(3) = median (x,1,n) ! Median of all
res(4) = median (x,rmid,n) ! upper hinge
res(5) = x(n) ! max value
end function fivenum
!==================
! Print the result
!==================
subroutine show (r,form )
real(kind=dp),dimension(5), intent(in) ::r
character (len=*), intent(in) :: form
write (*,form) r
end subroutine show
! ==============================================================================
! Calculate median of all elements of array x() between index ip1 and ip2 (incl)
! ==============================================================================
function median (x, ip1, ip2) result (med)
real (kind=dp), dimension(:), intent(in) :: x ! the entire array
integer, intent(in) :: ip1, ip2 ! end points of the part we need the median
real (kind=dp) :: med ! the calculated median
integer :: numberOfElements, midIndex ! size of the slice, index to middle of hte slice
numberOfElements = 1 + ip2-ip1
midIndex = ip1 + numberOfElements/2
if (mod (numberOfElements,2) .eq. 1) then ! Odd number of elements: take middle value
med = X(midIndex)
else ! Even number of values: average of 2 central values
med = (X(midIndex-1) + x(midIndex) ) / 2.
endif
end function median
! =========================
! sort array of real values
! =========================
recursive subroutine quicksort_real (arr, low, high)
real (kind=dp), dimension(:), intent(inout) :: arr
integer, intent(in) :: low, high
integer :: pivot_index
integer :: i, j, mid
real (kind=dp) :: pivot, temp
if (low .lt. high) then
! Assume the list is already "almost sorted", so use middle word as pivot.
mid = low + (high-low) / 2
pivot = arr(mid)
!Move pivot to the end
temp = arr(mid)
arr(mid) = arr(high)
arr(high)=temp
i = low - 1
do j = low, high - 1
if (arr(j) .le. pivot) then
i = i + 1
temp = arr(i)
arr(i) = arr(j)
arr(j) = temp
end if
end do
temp = arr(i+1)
arr(i+1) = arr(high)
arr(high) = temp
pivot_index = i + 1
call quicksort_real (arr, low, pivot_index - 1)
call quicksort_real (arr, pivot_index + 1, high)
end if
end subroutine quicksort_real
end program p_fivenum

View file

@ -0,0 +1,28 @@
require "table2"
local fmt = require "fmt"
local function fivenum(a)
a:sort()
local n5 = table.rep(5, 0)
local n = #a
local n4 = ((n + 3) // 2) / 2
local d = {1, n4, (n + 1) / 2, n + 1 - n4, n}
local e = 0
for d as de do
local floor = math.floor(de - 1)
local ceil = math.ceil(de - 1)
n5[e + 1] = 0.5 * (a[floor + 1] + a[ceil + 1])
e += 1
end
return n5
end
local x1 = {36, 40, 7, 39, 41, 15}
local x2 = {15, 6, 42, 41, 7, 36, 49, 40, 39, 47, 43}
local x3 = {
0.14082834, 0.09748790, 1.73131507, 0.87636009, -1.95059594,
0.73438555, -0.03035726, 1.46675970, -0.74621349, -0.72588772,
0.63905160, 0.61501527, -0.98983780, -1.00447874, -0.62759469,
0.66206163, 1.04312009, -0.10305385, 0.75775634, 0.32566578
}
for {x1, x2, x3} as x do fmt.lprint(fivenum(x)) end

View file

@ -0,0 +1,42 @@
import math
fn median(xay []f64, start int, end_inclusive int) f64 {
size := end_inclusive - start + 1
if size <= 0 { panic("Array slice cannot be empty") }
mir := start + size / 2
if size % 2 == 1 { return xay[mir] }
else { return (xay[mir - 1] + xay[mir]) / 2.0 }
}
fn fivenum(xay []f64) []f64 {
if xay.any(math.is_nan(it)) { panic("Unable to deal with arrays containing NaN") }
mut result := []f64{len: 5}
mut mir := 0
mut ay_sorted := xay.clone()
ay_sorted.sort()
result[0] = ay_sorted[0]
result[4] = ay_sorted[ay_sorted.len - 1]
result[2] = median(ay_sorted, 0, ay_sorted.len - 1)
mir = ay_sorted.len / 2
lower_end := if ay_sorted.len % 2 == 1 { mir } else { mir - 1 }
result[1] = median(ay_sorted, 0, lower_end)
result[3] = median(ay_sorted, mir, ay_sorted.len - 1)
return result
}
fn main() {
xl := [
[15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0, 39.0, 47.0, 43.0],
[36.0, 40.0, 7.0, 39.0, 41.0, 15.0],
[
0.14082834, 0.09748790, 1.73131507, 0.87636009, -1.95059594, 0.73438555,
-0.03035726, 1.46675970, -0.74621349, -0.72588772, 0.63905160, 0.61501527,
-0.98983780, -1.00447874, -0.62759469, 0.66206163, 1.04312009, -0.10305385,
0.75775634, 0.32566578,
],
]
for arr in xl {
println(fivenum(arr))
println("")
}
}