Jump to content

First class environments: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations, used output templates, reduced font size for 2nd output, simplified code.
(→‎{{header|jq}}: space vs time)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations, used output templates, reduced font size for 2nd output, simplified code.)
Line 1,318:
 
=={{header|REXX}}==
The formatting is sensativesensitive to a terminating Collatz sequence and is shown as blanks.   (that is,
<br>Columnonce widthsa are&nbsp; automatically'''1''' adjusted&nbsp; for(unity) their&nbsp; widthis (maximumfound, numberno more numbers are displayed in athat column).
 
<br>The '''hailstone''' function (subroutine) could be coded in-line to further comply with the task's requirement that
Column widths are automatically adjusted for their width (maximum number displayed in a column).
 
<br>The '''hailstone''' function (subroutine) could be coded in-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 program illustrates first-class1st─class environments (using the numbers from hailstone #sseq)*/
parse arg N .; if N=='' then N=12 /*Wasobtain Noptional defined?argument No,from usethe defaultCL.*/
w=length(if N) =='' | N=="," then N=12 /*theWas N defined? width (soNo, far)then foruse columnsdefault.*/
exitw=length(N) /*stickwidth a(so forkfar) in it,for we'recolumnar doneoutput.*/
@.=
do initi=1 for N; @.initi=initi; end /*i*/ /*initialize all the environments. */
 
do forever until @.0; @.0=1 /* ◄─── process all the environments. */
do k=1 for N; x=hailstone(k); w=max(w,length(x)) /*obtain next hailstone number in seq. */
@.k=@.k x w=max(w, length(x) ) /*wheredetermine the rubbermaximum meetswidth needed. the road*/
@.k=@.k x /* ◄─── where the rubber meets the road*/
end /*k*/
end end /*foreverk*/
end /*forever*/
 
count#=0 /* [↓] showdisplay the tabular results. */
do lines=-1 until _==''; _= /*process eacha line for each envenvironment. */
do j=1 for N /*process each environment.of the environments. */
select select /*choosedetermine how to process the line. */
when count#== 1 then _=_ right(words(@.j) - 1, w)
when lines==-1 then _=_ right(j, w) /*hdrthe header. */
when lines== 0 then _=_ right('', w, '"'") /*septhe separator. */
otherwise _=_ right(word(@.j, lines), w)
end /*select*/
end /*j*/
if count#==1 then count#=2
 
if _='' then #=# + 1 /*Null? Bump #. */
if count==1 then count=2
if #==1 then _=stripcopies(" "left(_,'T', w, "═");, N) if _=='' then count=count+1 /*if null,foot bumpseparator.*/
if count_\==1'' then _=copiessay strip(" "leftsubstr(''_, w2), "T"), N) /*footdisplay sepcounts.*/
end /*klines*/
if _\=='' then say substr(_,2) /*show the (foot) counts.*/
exit end /*linesstick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
exit /*stick a fork in it, we're done.*/
hailstone: procedure expose @.; parse arg y; _=word(@.y, words(@.y) )
/*─────────────────────────────────────HAILSTONE (Collatz) subroutine───*/
if _==1 then return '' ; @.0=0; if _//2==0 then return _%2; return _*3+1</lang>
hailstone: procedure expose @.; parse arg y; _=word(@.y, words(@.y))
'''{{out|output'''|text=&nbsp; when using the default input:}}
if _==1 then return '' ; @.0=0; if _//2==0 then return _%2; return _*3+1</lang>
'''output''' using the default input:
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
── ── ── ── ── ── ── ── ── ── ── ──
─── ─── ─── ─── ─── ─── ─── ─── ─── ─── ─── ───
1 2 3 4 5 6 7 8 9 10 11 12
1 10 2 16 3 22 4 28 5 34 6
5 1 8 10 11 2 14 16 17 3
16 4 5 34 1 7 8 52 10
8 2 16 17 22 4 26 5
4 1 8 52 11 2 13 16
2 4 26 34 1 40 8
1 2 13 17 20 4
1 40 52 10 2
20 26 5 1
10 13 16
5 40 8
16 20 4
8 10 2
4 5 1
2 16
1 8
4
2
1
══ ══ ══ ══ ══ ══ ══ ══ ══ ══ ══ ══
═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══
0 1 7 2 5 8 16 3 19 6 14 9
</pre>
'''{{out|output'''|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 60 </tt>}}
 
<pre style="height:90ex;overflow:scroll">
(Shown at three-quarter size.)
<pre style="font-size:75%;height:115ex">
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
──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ──── ────
Line 1,500 ⟶ 1,505:
════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════ ════
0 1 7 2 5 8 16 3 19 6 14 9 9 17 17 4 12 20 20 7 7 15 15 10 23 10 111 18 18 18 106 5 26 13 13 21 21 21 34 8 109 8 29 16 16 16 104 11 24 24 24 11 11 112 112 19 32 19 32 19
 
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.