Bin given limits: Difference between revisions

Content deleted Content added
Util (talk | contribs)
→‎{{header|Raku}}: Added Raku solution
m →‎{{header|REXX}}: added code to adjust for the true width of the counts.
Line 240: Line 240:
end /*j*/; return
end /*j*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
bins: parse arg nums; !.=0 /*!.: a zero─base array of bin counts.*/
bins: parse arg nums; !.=0; datum= words(nums); wc= length(datum) /*max width count. */
do j=1 for datum; x= word(nums, j)
wd= 0 /*max width data #s*/
do j=1 for words(nums); x= word(nums, j); wd= max(wd, length(x) )
do k=0 for # /*find the bin that this number is in. */
do k=0 for # /*find the bin that this number is in. */
if x< @.k then do; !.k= !.k + 1; iterate j; end /*bump the bin counter. */
if x< @.k then do; !.k= !.k + 1; iterate j; end /*bump the bin counter. */
Line 252: Line 251:
say center('' , 50, "═") /*show title separator. */
say center('' , 50, "═") /*show title separator. */
ge= '≥'; eq= ' count='
ge= '≥'; eq= ' count='
do j=0 for #; jm= j - 1; idx= right(@.j, wb); cnt= right(!.j, wd)
do j=0 for #; jm= j - 1; idx= right(@.j, wb); cnt= right(!.j, wc)
if j==0 then say pad left('', length(ge) +1+wb+2+length(..) )"<" idx eq cnt
if j==0 then say pad left('', length(ge) +1+wb+2+length(..) )"<" idx eq cnt
else say pad ge right(@.jm, wb) .. "<" idx eq cnt
else say pad ge right(@.jm, wb) .. "<" idx eq cnt
end /*j*/
end /*j*/
jm= j - 1; cnt= right(!.j, wd)
jm= j - 1; cnt= right(!.j, wc)
say pad ge right(@.jm, wb) left('', 3 + length(..) + wb) eq cnt
say pad ge right(@.jm, wb) left('', 3 + length(..) + wb) eq cnt
return</lang>
return</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
{{out|output|text=&nbsp; when using the internal default input:}}