Anonymous user
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
<br>
<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 solution have a ''single piece of code to be run repeatedly in each of these environments''.
<lang rexx>/*REXX program illustrates
parse arg N .
@.=
do
do forever until @.0; @.0=1 /* ◄─── process all the environments. */
do k=1 for N; x=hailstone(k)
@.k=@.k x /* ◄─── where the rubber meets the road*/
end /*k*/▼
end /*forever*/
select
if _='' then #=# + 1 /*Null? Bump #. */
▲ if count==1 then count=2
if #==1 then _=
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲exit /*stick a fork in it, we're done.*/
hailstone: procedure expose @.; parse arg y; _=word(@.y, words(@.y) )▼
▲hailstone: procedure expose @.; parse arg y; _=word(@.y, words(@.y))
▲if _==1 then return '' ; @.0=0; if _//2==0 then return _%2; return _*3+1</lang>
▲'''output''' using the default input:
<pre>
── ── ── ── ── ── ── ── ── ── ── ──
══ ══ ══ ══ ══ ══ ══ ══ ══ ══ ══ ══
</pre>
(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>
|