Bin given limits: Difference between revisions

add FreeBASIC
(→‎{{header|Ruby}}: output corrected)
(add FreeBASIC)
Line 590:
59 members in [720, ∞)
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>sub binlims( dat() as integer, limits() as integer, bins() as uinteger )
dim as uinteger n = ubound(limits), j, i
for i = 0 to ubound(dat)
if dat(i)<limits(0) then
bins(0) += 1
elseif dat(i) >= limits(n) then
bins(n+1) += 1
else
for j = 1 to n
if dat(i)<limits(j) then
bins(j) += 1
exit for
end if
next j
end if
next i
end sub
'example 1
dim as integer limits1(0 to ...) = {23, 37, 43, 53, 67, 83}
dim as integer dat1(0 to ...) = {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}
dim as uinteger bins1(0 to ubound(limits1)+1)
binlims( dat1(), limits1(), bins1() )
print "=====EXAMPLE ONE====="
print "< ";limits1(0);": ";bins1(0)
for i as uinteger = 1 to ubound(limits1)
print ">= ";limits1(i-1);" and < ";limits1(i);": ";bins1(i)
next i
print ">= ";limits1(ubound(limits1));": ";bins1(ubound(bins1))
print
 
'example 2
dim as integer limits2(0 to ...) = {14, 18, 249, 312, 389, 392, 513, 591, 634, 720}
dim as integer dat2(0 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}
redim as uinteger bins2(0 to ubound(limits2)+1)
 
binlims( dat2(), limits2(), bins2() )
print "=====EXAMPLE TWO====="
print "< ";limits2(0);": ";bins2(0)
for i as uinteger = 1 to ubound(limits2)
print ">= ";limits2(i-1);" and < ";limits2(i);": ";bins2(i)
next i
print ">= ";limits2(ubound(limits2));": ";bins2(ubound(bins2))</lang>
{{out}}
<pre>=====EXAMPLE ONE=====
< 23: 11
>= 23 and < 37: 4
>= 37 and < 43: 2
>= 43 and < 53: 6
>= 53 and < 67: 9
>= 67 and < 83: 5
>= 83: 13
 
=====EXAMPLE TWO=====
< 14: 3
>= 14 and < 18: 0
>= 18 and < 249: 44
>= 249 and < 312: 10
>= 312 and < 389: 16
>= 389 and < 392: 2
>= 392 and < 513: 28
>= 513 and < 591: 16
>= 591 and < 634: 6
>= 634 and < 720: 16
>= 720: 59</pre>
 
=={{header|Go}}==
781

edits