First class environments: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments. added wording to the REXX section header.
(Added Wren)
m (→‎{{header|REXX}}: added/changed whitespace and comments. added wording to the REXX section header.)
Line 1,677:
<br>once a &nbsp; '''1''' &nbsp; (unity) &nbsp; is found, no more numbers are displayed in that column).
 
Column widths are automatically adjusted for their width &nbsp;(the maximum decimal digits displayed in a column).
 
The '''hailstone''' function (subroutine) could be coded in-linein─line to further comply with the task's requirement that
<br>the solution have a &nbsp; ''single piece of code to be run repeatedly in each of these environments''.
<lang rexx>/*REXX programpgm illustrates N 1st─class environments (using the numbers from a hailstone seq).*/
parse arg Nn . /*obtain optional argument from the CL.*/
if Nn=='' | Nn=="," then Nn=12 12 /*Was N defined? No, then use default.*/
w@.=length(N) /*widthinitialize the array (so far)@. forto columnar outputnulls.*/
do i=1 for n; @.i= i /* " environments to an index. */
@.=
do i=1 for N; @.i=i; end /*i*/ end /*initialize all the environments. i*/
w= length(n) /*width (so far) for columnar output.*/
 
do forever until @.0; @.0=1 1 /* ◄─── process all the environments. */
do k=1 for Nn; x= hailstone(k) /*obtain next hailstone number in seq. */
w= max(w, length(x) ) /*determine the maximum width needed. */
@.k= @.k x /* ◄─── where the rubber meets the road*/
end /*k*/
end /*forever*/
#=0 0 /* [↓] display the tabular results. */
do lines=-1 until _=''; _= /*process a line for each environment. */
do j=1 for Nn /*process each of the environments. */
select /*determine how to process the line. */
when #== 1 then _= _ right(words(@.j) - 1, w) /*environment count.*/
when lines==-1 then _= _ right(j, w) /*the title (header. )*/
when lines== 0 then _= _ right('', w, "─") /*the separator. line*/
otherwise _= _ right(word(@.j, lines), w)
end /*select*/
end /*j*/
 
if #==1 then #=2
if _#=''=1 then #=# + 12 /*Nullseparator line? Bump #. */
if #_==1'' then _#=copies(" "left('',# + 1 w, "═"), N) /*footNull? separator Bump the #.*/
if _\#=''=1 then say_= stripcopies(" substr"left(_'', 2)w, "T"), N) /*displaythe foot counts.separator*/
if _\='' then say strip( substr(_, 2), "T") /*display the counts*/
end /*lines*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
hailstone: procedure expose @.; parse arg y; _= word(@.y, words(@.y) )
if _==1 then return ''; @.0= 0; if _//2 then return _*3 + 1; return _%2</lang>
{{out|output|text=&nbsp; when using the default input:}}
 
(Shown at three-fourthsthree─fourths size.)
<pre style="font-size:75%>
1 2 3 4 5 6 7 8 9 10 11 12
Line 1,744 ⟶ 1,746:
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 60 </tt>}}
 
(Shown at two-thirdstwo─thirds size.)
<pre style="font-size:67%;height:185ex">
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60