Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -0,0 +1,42 @@
|
|||
property bins : {}
|
||||
|
||||
local limits, theData, n, i, p, flag, output
|
||||
set limits to {14, 18, 249, 312, 389, 392, 513, 591, 634, 720}
|
||||
set theData to {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}
|
||||
|
||||
repeat (count limits) + 1 times
|
||||
set end of bins to 0
|
||||
end repeat
|
||||
|
||||
repeat with n in theData
|
||||
set flag to false
|
||||
repeat with i from 1 to count limits
|
||||
if n < item i of limits then
|
||||
set flag to true
|
||||
exit repeat
|
||||
end if
|
||||
end repeat
|
||||
if flag then
|
||||
set item i of bins to (item i of bins) + 1
|
||||
else
|
||||
set item -1 of bins to (item -1 of bins) + 1
|
||||
end if
|
||||
end repeat
|
||||
set p to item 1 of limits
|
||||
set output to "< " & p & " := " & (item 1 of bins) & linefeed
|
||||
repeat with i from 2 to count limits
|
||||
set n to item i of limits
|
||||
set output to output & ">= " & p & " .. < " & n & " := " & (item i of bins) & linefeed
|
||||
set p to n
|
||||
end repeat
|
||||
set output to output & ">= " & p & " := " & (item -1 of bins)
|
||||
get output
|
||||
43
Task/Bin-given-limits/Crystal/bin-given-limits.cr
Normal file
43
Task/Bin-given-limits/Crystal/bin-given-limits.cr
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
def bin (limits, seq)
|
||||
bins = Array.new limits.size+1, 0
|
||||
seq.each do |v|
|
||||
bins[limits.bsearch_index {|l, _| v < l } || -1] += 1
|
||||
end
|
||||
bins
|
||||
end
|
||||
|
||||
def print_bins (limits, bins)
|
||||
limit_width = limits.values_at(0, -1).map(&.to_s.size).max
|
||||
tally_width = bins.max.to_s.size
|
||||
bins.each_with_index do |n, i|
|
||||
left = if i > 0; limits[i-1] end
|
||||
right = if i < limits.size; limits[i] end
|
||||
printf "%*s %s n %s %*s ⇒ %*s\n",
|
||||
limit_width, left, left ? "≤" : " ",
|
||||
right ? "<" : " ", limit_width, right,
|
||||
tally_width, n
|
||||
end
|
||||
end
|
||||
|
||||
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]
|
||||
|
||||
puts "P. 1"
|
||||
print_bins(limits, bin(limits, data))
|
||||
puts
|
||||
|
||||
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]
|
||||
|
||||
puts "P. 2"
|
||||
print_bins(limits, bin(limits, data))
|
||||
|
|
@ -1,13 +1,10 @@
|
|||
global limits[] data[] .
|
||||
#
|
||||
proc count . .
|
||||
proc count .
|
||||
len cnt[] len limits[] + 1
|
||||
#
|
||||
for e in data[]
|
||||
for i to len limits[]
|
||||
if e < limits[i]
|
||||
break 1
|
||||
.
|
||||
if e < limits[i] : break 1
|
||||
.
|
||||
cnt[i] += 1
|
||||
.
|
||||
|
|
|
|||
60
Task/Bin-given-limits/XPL0/bin-given-limits.xpl0
Normal file
60
Task/Bin-given-limits/XPL0/bin-given-limits.xpl0
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
include xpllib; \for Print
|
||||
int Bin(10+1);
|
||||
def Marker = 0;
|
||||
|
||||
proc PrintBins(Limits, Len);
|
||||
int Limits, Len;
|
||||
int I;
|
||||
[Print(" < %3d:%3d\n", Limits(0), Bin(0));
|
||||
for I:= 1 to Len-1 do
|
||||
Print(">= %3d and < %3d:%3d\n", Limits(I-1), Limits(I), Bin(I));
|
||||
Print(">= %3d :%3d\n", Limits(Len-1), Bin(Len));
|
||||
];
|
||||
|
||||
proc TallyBins(Limits, Len, Data);
|
||||
int Limits, Len, Data;
|
||||
int I, J, D;
|
||||
[for I:= 0 to Len do
|
||||
Bin(I):= 0;
|
||||
I:= 0;
|
||||
loop [D:= Data(I);
|
||||
if D = Marker then quit;
|
||||
I:= I+1;
|
||||
for J:= 0 to Len-1 do \for each limit
|
||||
if D < Limits(J) then
|
||||
[Bin(J):= Bin(J)+1;
|
||||
J:= Len; \exit for loop with J = Len+1
|
||||
];
|
||||
if J = Len then \>= last limit
|
||||
Bin(J):= Bin(J)+1;
|
||||
];
|
||||
];
|
||||
|
||||
int Limits, Data;
|
||||
[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, Marker];
|
||||
TallyBins(Limits, 6, Data);
|
||||
PrintBins(Limits, 6);
|
||||
CrLf(0);
|
||||
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, Marker];
|
||||
TallyBins(Limits, 10, Data);
|
||||
PrintBins(Limits, 10);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue