First class environments: Difference between revisions
Content added Content deleted
(→{{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: | Line 1,318: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
The formatting is |
The formatting is sensitive to a terminating Collatz sequence and is shown as blanks (that is, |
||
<br> |
<br>once a '''1''' (unity) is found, no more numbers are displayed in that column). |
||
⚫ | |||
Column widths are automatically adjusted for their width (maximum number displayed in a column). |
|||
⚫ | |||
<br>the solution have a ''single piece of code to be run repeatedly in each of these environments''. |
<br>the solution have a ''single piece of code to be run repeatedly in each of these environments''. |
||
<lang rexx>/*REXX program illustrates |
<lang rexx>/*REXX program illustrates 1st─class environments (using the numbers from hailstone seq)*/ |
||
parse arg N . |
parse arg N . /*obtain optional argument from the CL.*/ |
||
if N=='' | N=="," then N=12 /*Was N defined? No, then use default.*/ |
|||
⚫ | |||
@.= |
@.= |
||
do |
do i=1 for N; @.i=i; end /*i*/ /*initialize all the environments. */ |
||
do forever until @.0; @.0=1 /* ◄─── process all environments.*/ |
do forever until @.0; @.0=1 /* ◄─── process all the environments. */ |
||
do k=1 for N; x=hailstone(k) |
do k=1 for N; 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 /* [↓] display the tabular results. */ |
|||
do lines=-1 until _=''; _= /*process a line for each environment. */ |
|||
do j=1 for N /*process each of the environments. */ |
|||
select /*determine how to process the line. */ |
|||
when #== 1 then _=_ right(words(@.j) - 1, w) |
|||
when lines==-1 then _=_ right(j, w) /*the header. */ |
|||
when lines== 0 then _=_ right('', w, "─") /*the separator. */ |
|||
otherwise _=_ right(word(@.j, lines), w) |
|||
end /*select*/ |
|||
end /*j*/ |
|||
⚫ | |||
if _='' then #=# + 1 /*Null? Bump #. */ |
|||
⚫ | |||
_= |
if #==1 then _=copies(" "left('', w, "═"), N) /*foot separator.*/ |
||
if _\='' then say strip( substr(_, 2), "T") /*display counts.*/ |
|||
⚫ | |||
if _\=='' then say substr(_,2) /*show the (foot) counts.*/ |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
/*─────────────────────────────────────HAILSTONE (Collatz) subroutine───*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<pre> |
<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> |
</pre> |
||
{{out|output|text= when using the input of: <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 |
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: | Line 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 |
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> |
</pre> |
||