Bin given limits: Difference between revisions

Content added Content deleted
m (Correction to task description.)
m (→‎{{header|REXX}}: simplified some code.)
Line 553: Line 553:
exit 0 /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
lims: parse arg limList; #= words(limList); wb= 0 /*max width binLims*/
bins: parse arg nums; !.= 0; datum= words(nums); wc= length(datum) /*max width count.*/
do j=1 for #; _= j - 1; @._= word(limList, j); wb= max(wb, length(@._) )
end /*j*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
bins: parse arg nums; !.=0; datum= words(nums); wc= length(datum) /*max width count. */
do j=1 for datum; x= word(nums, j)
do j=1 for datum; x= word(nums, j)
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 a bin count*/
end /*k*/
end /*k*/
!.k= !.k + 1 /*a number is larger than any bin limit*/
!.k= !.k + 1 /*number is > the highest bin specified*/
end /*j*/; return
end /*j*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
lims: parse arg limList; #= words(limList); wb= 0 /*max width binLim*/
do j=1 for #; _= j - 1; @._= word(limList, j); wb= max(wb, length(@._) )
end /*j*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: say center(' 'arg(1)" ", 51 ); $= left('', 9) /*$: for indentation.*/
show: parse arg t; say center(t, 51 ); $= left('', 9) /*$: for indentation*/
say center('' , 51, "═") /*show title separator. */
say center('', 51, "═") /*show title separator.*/
jp= #-1; ge= '≥'; eq= ' count='
jp= # - 1; ge= '≥'; le='<'; eq= ' count='
do j=0 for #; jm= j - 1; idx= right(@.j, wb); cnt= right(!.j, wc)
do j=0 for #; jm= j - 1; bin= right(@.j, wb)
if j==0 then say $ left('', length(ge)+1+wb+2+length(..))"<" idx eq right(!.j,wc)
if j==0 then say $ left('', length(ge) +3+wb+length(..) )le bin eq right(!.j, wc)
else say $ ge right(@.jm, wb) .. "<" idx eq right(!.j,wc)
else say $ ge right(@.jm, wb) .. le bin eq right(!.j, wc)
if j==jp then say $ ge right(@.jp, wb) left('', 3+length(..)+wb) eq right(!.#,wc)
if j==jp then say $ ge right(@.jp,wb) left('', 3+length(..)+wb) eq right(!.#, wc)
end /*j*/; return</lang>
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
<pre>