Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
8
Task/Bin-given-limits/Ada/bin-given-limits-1.adb
Normal file
8
Task/Bin-given-limits/Ada/bin-given-limits-1.adb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package binning is
|
||||
type Nums_Array is array (Natural range <>) of Integer;
|
||||
function Is_Sorted (Item : Nums_Array) return Boolean;
|
||||
subtype Limits_Array is Nums_Array with
|
||||
Dynamic_Predicate => Is_Sorted (Limits_Array);
|
||||
function Bins (Limits : Limits_Array; Data : Nums_Array) return Nums_Array;
|
||||
procedure Print (Limits : Limits_Array; Bin_Result : Nums_Array);
|
||||
end binning;
|
||||
69
Task/Bin-given-limits/Ada/bin-given-limits-2.adb
Normal file
69
Task/Bin-given-limits/Ada/bin-given-limits-2.adb
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
pragma Ada_2012;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||
|
||||
package body binning is
|
||||
|
||||
---------------
|
||||
-- Is_Sorted --
|
||||
---------------
|
||||
|
||||
function Is_Sorted (Item : Nums_Array) return Boolean is
|
||||
begin
|
||||
return
|
||||
(for all i in Item'First .. Item'Last - 1 => Item (i) < Item (i + 1));
|
||||
end Is_Sorted;
|
||||
|
||||
----------
|
||||
-- Bins --
|
||||
----------
|
||||
|
||||
function Bins (Limits : Limits_Array; Data : Nums_Array) return Nums_Array
|
||||
is
|
||||
Result : Nums_Array (Limits'First .. Limits'Last + 1) := (others => 0);
|
||||
Bin_Index : Natural;
|
||||
begin
|
||||
for value of Data loop
|
||||
Bin_Index := Result'First;
|
||||
for I in reverse Limits'Range loop
|
||||
if value >= Limits (I) then
|
||||
Bin_Index := I + 1;
|
||||
exit;
|
||||
end if;
|
||||
end loop;
|
||||
Result (Bin_Index) := Result (Bin_Index) + 1;
|
||||
end loop;
|
||||
return Result;
|
||||
end Bins;
|
||||
|
||||
-----------
|
||||
-- Print --
|
||||
-----------
|
||||
|
||||
procedure Print (Limits : Limits_Array; Bin_Result : Nums_Array) is
|
||||
begin
|
||||
if Limits'Length = 0 then
|
||||
return;
|
||||
end if;
|
||||
Put (" < ");
|
||||
Put (Item => Limits (Limits'First), Width => 3);
|
||||
Put (": ");
|
||||
Put (Item => Bin_Result (Bin_Result'First), Width => 2);
|
||||
New_Line;
|
||||
for i in Limits'First + 1 .. Limits'Last loop
|
||||
Put (">= ");
|
||||
Put (Item => Limits (i - 1), Width => 3);
|
||||
Put (" and < ");
|
||||
Put (Item => Limits (i), Width => 3);
|
||||
Put (": ");
|
||||
Put (Item => Bin_Result (i), Width => 2);
|
||||
New_Line;
|
||||
end loop;
|
||||
Put (">= ");
|
||||
Put (Item => Limits (Limits'Last), Width => 3);
|
||||
Put (" : ");
|
||||
Put (Item => Bin_Result (Bin_Result'Last), Width => 2);
|
||||
New_Line;
|
||||
end Print;
|
||||
|
||||
end binning;
|
||||
34
Task/Bin-given-limits/Ada/bin-given-limits-3.adb
Normal file
34
Task/Bin-given-limits/Ada/bin-given-limits-3.adb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with binning; use binning;
|
||||
|
||||
procedure Main is
|
||||
Limits_1 : Limits_Array := (23, 37, 43, 53, 67, 83);
|
||||
Data_1 : Nums_Array :=
|
||||
(95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92,
|
||||
83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6,
|
||||
98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55);
|
||||
Limits_2 : Limits_Array := (14, 18, 249, 312, 389, 392, 513, 591, 634, 720);
|
||||
Data_2 : Nums_Array :=
|
||||
(445, 814, 519, 697, 700, 130, 255, 889, 481, 122, 932, 77, 323, 525, 570,
|
||||
219, 367, 523, 442, 933, 416, 589, 930, 373, 202, 253, 775, 47, 731, 685,
|
||||
293, 126, 133, 450, 545, 100, 741, 583, 763, 306, 655, 267, 248, 477,
|
||||
549, 238, 62, 678, 98, 534, 622, 907, 406, 714, 184, 391, 913, 42, 560,
|
||||
247, 346, 860, 56, 138, 546, 38, 985, 948, 58, 213, 799, 319, 390, 634,
|
||||
458, 945, 733, 507, 916, 123, 345, 110, 720, 917, 313, 845, 426, 9, 457,
|
||||
628, 410, 723, 354, 895, 881, 953, 677, 137, 397, 97, 854, 740, 83, 216,
|
||||
421, 94, 517, 479, 292, 963, 376, 981, 480, 39, 257, 272, 157, 5, 316,
|
||||
395, 787, 942, 456, 242, 759, 898, 576, 67, 298, 425, 894, 435, 831, 241,
|
||||
989, 614, 987, 770, 384, 692, 698, 765, 331, 487, 251, 600, 879, 342,
|
||||
982, 527, 736, 795, 585, 40, 54, 901, 408, 359, 577, 237, 605, 847, 353,
|
||||
968, 832, 205, 838, 427, 876, 959, 686, 646, 835, 127, 621, 892, 443,
|
||||
198, 988, 791, 466, 23, 707, 467, 33, 670, 921, 180, 991, 396, 160, 436,
|
||||
717, 918, 8, 374, 101, 684, 727, 749);
|
||||
Bin_1 : Nums_Array := Bins (Limits => Limits_1, Data => Data_1);
|
||||
Bin_2 : Nums_Array := Bins (Limits => Limits_2, Data => Data_2);
|
||||
begin
|
||||
Put_Line ("Example 1:");
|
||||
Print (Limits => Limits_1, Bin_Result => Bin_1);
|
||||
New_Line;
|
||||
Put_Line ("Example 2:");
|
||||
Print (Limits => Limits_2, Bin_Result => Bin_2);
|
||||
end Main;
|
||||
98
Task/Bin-given-limits/Fortran/bin-given-limits.f
Normal file
98
Task/Bin-given-limits/Fortran/bin-given-limits.f
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
!
|
||||
! Bin given limits
|
||||
! 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 (V8.6) does compile this code because it
|
||||
! does not like the dimension (*) of the parameters
|
||||
! U.B., January 2026
|
||||
!==============================================================================
|
||||
program binLimits
|
||||
|
||||
implicit none
|
||||
|
||||
! Limits and Data for first example from task description
|
||||
integer, parameter :: limits1 (*) = [23, 37, 43, 53, 67, 83 ]
|
||||
integer, parameter :: values1 (*) = [95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, &
|
||||
16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55]
|
||||
|
||||
! Second example
|
||||
integer, parameter :: limits2 (*) = [14, 18, 249, 312, 389, 392, 513, 591, 634, 720]
|
||||
integer, parameter :: values2 (*) = [445,814,519,697,700,130,255,889,481,122,932, 77,323,525,570,219,367,523,442,933, &
|
||||
416,589,930,373,202,253,775, 47,731,685,293,126,133,450,545,100,741,583,763,306, &
|
||||
655,267,248,477,549,238, 62,678, 98,534,622,907,406,714,184,391,913, 42,560,247, &
|
||||
346,860, 56,138,546, 38,985,948, 58,213,799,319,390,634,458,945,733,507,916,123, &
|
||||
345,110,720,917,313,845,426, 9,457,628,410,723,354,895,881,953,677,137,397, 97, &
|
||||
854,740, 83,216,421, 94,517,479,292,963,376,981,480, 39,257,272,157, 5,316,395, &
|
||||
787,942,456,242,759,898,576, 67,298,425,894,435,831,241,989,614,987,770,384,692, &
|
||||
698,765,331,487,251,600,879,342,982,527,736,795,585, 40, 54,901,408,359,577,237, &
|
||||
605,847,353,968,832,205,838,427,876,959,686,646,835,127,621,892,443,198,988,791, &
|
||||
466, 23,707,467, 33,670,921,180,991,396,160,436,717,918, 8,374,101,684,727,749]
|
||||
|
||||
call solve (limits1, size(limits1), values1, size(values1))
|
||||
call solve (limits2, size(limits2), values2, size(values2))
|
||||
|
||||
contains
|
||||
|
||||
! ==================================================
|
||||
! Create array of Histogram bins, then print results
|
||||
! ==================================================
|
||||
subroutine solve (l, nl, v,nv)
|
||||
integer, intent(in) :: nl, nv ! Array sizes
|
||||
integer, intent(in) :: l(nl), v(nv) ! Limits and Data arryays
|
||||
integer :: hist (0:nl) ! THe resultant histogram
|
||||
|
||||
call build_Histogram (l,nl,v,nv,hist)
|
||||
call print_LimitsAndHistogram (l,nl,hist)
|
||||
|
||||
end subroutine solve
|
||||
|
||||
|
||||
! ==============================
|
||||
! Create array of Histogram bins
|
||||
! ==============================
|
||||
subroutine build_Histogram (l,nl,v,nv,hist)
|
||||
|
||||
integer, intent(in) :: nl, nv ! Array sizes
|
||||
integer, intent(in) :: l(nl), v(nv) ! Limits and Data arryays
|
||||
integer,intent(out) :: hist (0:nl) ! The resultant histogram
|
||||
|
||||
integer :: iv, il ! Loop indices into values and limits
|
||||
|
||||
hist = 0
|
||||
do iv=1, nv
|
||||
! If number of limits nl is small (here: 5 resp. 10), linear search for bin is sufficient.
|
||||
! for large nl consider to use binary search, that can be more efficient.
|
||||
do il= nl, 1, -1
|
||||
if (v(iv) .ge. l(il)) then
|
||||
hist(il) = hist(il) + 1
|
||||
exit
|
||||
else if (il .eq. 1) then
|
||||
hist(0) = hist(0) + 1
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
|
||||
end subroutine build_Histogram
|
||||
|
||||
subroutine print_LimitsAndHistogram (l,nl,hist)
|
||||
|
||||
integer, intent(in) :: nl ! Array size
|
||||
integer, intent(in) :: l(nl) ! Limits to print
|
||||
integer, intent(in) :: hist (0:nl) ! Histogram values to print
|
||||
|
||||
integer :: il ! Loop index
|
||||
|
||||
do il=0, nl
|
||||
if (il .eq. 0) then
|
||||
write (*,'(" < ", i3, ": ", i3)') l(1), hist(il)
|
||||
else if (il .lt. nl) then
|
||||
write (*,'(">= ", i3, " ... < ", i3, ": ", i3)') l(il), l(il+1), hist(il)
|
||||
else
|
||||
write (*,'(">= ", i3, " : ", i3)') l(il) , hist(il)
|
||||
end if
|
||||
end do
|
||||
write (*,*) ! 1 empty line
|
||||
|
||||
end subroutine print_LimitsAndHistogram
|
||||
|
||||
end program binLimits
|
||||
43
Task/Bin-given-limits/Icon/bin-given-limits.icon
Normal file
43
Task/Bin-given-limits/Icon/bin-given-limits.icon
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
procedure main()
|
||||
limits := [23, 37, 43, 53, 67, 83]
|
||||
data := [95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,
|
||||
61,54,58,47,16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,
|
||||
45,64,60,29,49,36,43,55]
|
||||
write("1st limits and data set:")
|
||||
bins := buildbins(limits, data)
|
||||
summary(limits, bins)
|
||||
|
||||
limits := [14, 18, 249, 312, 389, 392, 513, 591, 634, 720]
|
||||
data := [445,814,519,697,700,130,255,889,481,122,932, 77,323,525,570,
|
||||
219,367,523,442,933,416,589,930,373,202,253,775, 47,731,685,
|
||||
293,126,133,450,545,100,741,583,763,306,655,267,248,477,549,
|
||||
238, 62,678, 98,534,622,907,406,714,184,391,913, 42,560,247,
|
||||
346,860, 56,138,546, 38,985,948, 58,213,799,319,390,634,458,
|
||||
945,733,507,916,123,345,110,720,917,313,845,426, 9,457,628,
|
||||
410,723,354,895,881,953,677,137,397, 97,854,740, 83,216,421,
|
||||
94,517,479,292,963,376,981,480, 39,257,272,157, 5,316,395,
|
||||
787,942,456,242,759,898,576, 67,298,425,894,435,831,241,989,
|
||||
614,987,770,384,692,698,765,331,487,251,600,879,342,982,527,
|
||||
736,795,585, 40, 54,901,408,359,577,237,605,847,353,968,832,
|
||||
205,838,427,876,959,686,646,835,127,621,892,443,198,988,791,
|
||||
466, 23,707,467, 33,670,921,180,991,396,160,436,717,918, 8,
|
||||
374,101,684,727,749]
|
||||
write("\n2nd limits and data set:")
|
||||
bins := buildbins(limits, data)
|
||||
summary(limits, bins)
|
||||
end
|
||||
|
||||
procedure buildbins(limits, data)
|
||||
bins := list(*limits+1, 0)
|
||||
every item := !data do
|
||||
if item < (limits[i := 1 to *limits]) then bins[i] +:= 1
|
||||
else bins[*limits+1] +:= 1
|
||||
return bins
|
||||
end
|
||||
|
||||
procedure summary(limits, bins)
|
||||
write(repl(" ",8)," < ",right(limits[1],5)," -> ",right(bins[1],4))
|
||||
every i := 2 to *limits do
|
||||
write(right(limits[i-1],8)," .. ",right(limits[i],4)," -> ",right(bins[i],4))
|
||||
write(right("> ",11),right(limits[*limits],5)," -> ",right(bins[*bins],4))
|
||||
end
|
||||
43
Task/Bin-given-limits/Perl/bin-given-limits-3.pl
Normal file
43
Task/Bin-given-limits/Perl/bin-given-limits-3.pl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict; # https://rosettacode.org/wiki/Bin_given_limits
|
||||
use warnings;
|
||||
use List::MoreUtils qw( upper_bound slide );
|
||||
|
||||
for (
|
||||
{
|
||||
example => 1,
|
||||
limits => [23, 37, 43, 53, 67, 83],
|
||||
data => [
|
||||
95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47,
|
||||
16, 8, 9,32,84,7,87,46,19,30,37,96, 6,98,40,79,97,45,64,60,29,49,36,43,55
|
||||
]
|
||||
},
|
||||
{
|
||||
example => 2,
|
||||
limits => [14, 18, 249, 312, 389, 392, 513, 591, 634, 720],
|
||||
data => [
|
||||
445,814,519,697,700,130,255,889,481,122,932, 77,323,525,570,219,367,523,442,933,
|
||||
416,589,930,373,202,253,775, 47,731,685,293,126,133,450,545,100,741,583,763,306,
|
||||
655,267,248,477,549,238, 62,678, 98,534,622,907,406,714,184,391,913, 42,560,247,
|
||||
346,860, 56,138,546, 38,985,948, 58,213,799,319,390,634,458,945,733,507,916,123,
|
||||
345,110,720,917,313,845,426, 9,457,628,410,723,354,895,881,953,677,137,397, 97,
|
||||
854,740, 83,216,421, 94,517,479,292,963,376,981,480, 39,257,272,157, 5,316,395,
|
||||
787,942,456,242,759,898,576, 67,298,425,894,435,831,241,989,614,987,770,384,692,
|
||||
698,765,331,487,251,600,879,342,982,527,736,795,585, 40, 54,901,408,359,577,237,
|
||||
605,847,353,968,832,205,838,427,876,959,686,646,835,127,621,892,443,198,988,791,
|
||||
466, 23,707,467, 33,670,921,180,991,396,160,436,717,918, 8,374,101,684,727,749
|
||||
]
|
||||
}
|
||||
)
|
||||
{
|
||||
print "\nExample $_->{example}:\n";
|
||||
my @bins;
|
||||
my @limits = @{ $_->{limits} };
|
||||
for my $n ( @{ $_->{data} } )
|
||||
{
|
||||
$bins[ upper_bound { $_ <=> $n } @limits ]++;
|
||||
}
|
||||
slide { printf "%4s <= value < %4s : %d\n", $a, $b, shift @bins // 0 }
|
||||
'-inf', @limits, '+inf';
|
||||
}
|
||||
63
Task/Bin-given-limits/Pluto/bin-given-limits.pluto
Normal file
63
Task/Bin-given-limits/Pluto/bin-given-limits.pluto
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
require "table2"
|
||||
local fmt = require "fmt"
|
||||
|
||||
local function bisect_right(array, x, low = 1, high = #array + 1)
|
||||
while low < high do
|
||||
local middle = (low + high) // 2
|
||||
if x < array[middle] then
|
||||
high = middle
|
||||
else
|
||||
low = middle + 1
|
||||
end
|
||||
end
|
||||
return low
|
||||
end
|
||||
|
||||
local function bin_it(limits, data)
|
||||
local bins = table.rep(#limits + 1, 0)
|
||||
for data as d do
|
||||
bins[bisect_right(limits, d)] += 1
|
||||
end
|
||||
return bins
|
||||
end
|
||||
|
||||
local function bin_print(limits, bins)
|
||||
fmt.print(" < %3d := %3d", limits[1], bins[1])
|
||||
local z = limits:zip(limits:slice(2)):zip(bins:slice(2))
|
||||
for z as p do
|
||||
local [lo, hi] = p[1]
|
||||
fmt.print(">= %3d .. < %3d := %3d", lo, hi, p[2])
|
||||
end
|
||||
fmt.print(">= %3d := %3d", limits:back(), bins:back())
|
||||
end
|
||||
|
||||
print("RC FIRST EXAMPLE:")
|
||||
local limits = {23, 37, 43, 53, 67, 83}
|
||||
local data = {
|
||||
95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92,
|
||||
83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6,
|
||||
98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55
|
||||
}
|
||||
local bins = bin_it(limits, data)
|
||||
bin_print(limits, bins)
|
||||
|
||||
print("\nRC SECOND EXAMPLE:")
|
||||
limits = {14, 18, 249, 312, 389, 392, 513, 591, 634, 720}
|
||||
data = {
|
||||
445, 814, 519, 697, 700, 130, 255, 889, 481, 122, 932, 77, 323, 525, 570,
|
||||
219, 367, 523, 442, 933, 416, 589, 930, 373, 202, 253, 775, 47, 731, 685,
|
||||
293, 126, 133, 450, 545, 100, 741, 583, 763, 306, 655, 267, 248, 477, 549,
|
||||
238, 62, 678, 98, 534, 622, 907, 406, 714, 184, 391, 913, 42, 560, 247,
|
||||
346, 860, 56, 138, 546, 38, 985, 948, 58, 213, 799, 319, 390, 634, 458,
|
||||
945, 733, 507, 916, 123, 345, 110, 720, 917, 313, 845, 426, 9, 457, 628,
|
||||
410, 723, 354, 895, 881, 953, 677, 137, 397, 97, 854, 740, 83, 216, 421,
|
||||
94, 517, 479, 292, 963, 376, 981, 480, 39, 257, 272, 157, 5, 316, 395,
|
||||
787, 942, 456, 242, 759, 898, 576, 67, 298, 425, 894, 435, 831, 241, 989,
|
||||
614, 987, 770, 384, 692, 698, 765, 331, 487, 251, 600, 879, 342, 982, 527,
|
||||
736, 795, 585, 40, 54, 901, 408, 359, 577, 237, 605, 847, 353, 968, 832,
|
||||
205, 838, 427, 876, 959, 686, 646, 835, 127, 621, 892, 443, 198, 988, 791,
|
||||
466, 23, 707, 467, 33, 670, 921, 180, 991, 396, 160, 436, 717, 918, 8,
|
||||
374, 101, 684, 727, 749
|
||||
}
|
||||
bins = bin_it(limits, data)
|
||||
bin_print(limits, bins)
|
||||
5
Task/Bin-given-limits/Uiua/bin-given-limits.uiua
Normal file
5
Task/Bin-given-limits/Uiua/bin-given-limits.uiua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Limits ← [23 37 43 53 67 83]
|
||||
Data ← [95 21 94 12 99 4 70 75 83 93 52 80 57 5 53 86 65 17 92 83 71 61 54 58 47
|
||||
16 8 9 32 84 7 87 46 19 30 37 96 6 98 40 79 97 45 64 60 29 49 36 43 55]
|
||||
⊕⧻⤚≡(˜⨂1>)⊙¤⊙⟜∘ Data Limits # Fill bins
|
||||
≡(&p$"Bin < _ has:\t_"°⊟)⍉⬚∞˜⊟ # Count contents
|
||||
Loading…
Add table
Add a link
Reference in a new issue