Anonymous user
Zig-zag matrix: Difference between revisions
m
→{{header|REXX}}: added a matrix that starts with unity, another with negative increment, added/changed comments and whitespace, added a subroutine, used templates for the output sections.
(→{{header|Octave}}: A solution inspired by Rascal) |
m (→{{header|REXX}}: added a matrix that starts with unity, another with negative increment, added/changed comments and whitespace, added a subroutine, used templates for the output sections.) |
||
Line 5,029:
<lang rexx>/*REXX program produces and displays a zig─zag matrix (a square array). */
parse arg n start inc . /*obtain optional arguments from the CL*/
if n=='' | n=="," then n=
if start=='' | start=="," then start=
if inc=='' | inc=="," then inc=
row= 1;
do j=start by inc for size; @.row.col= j
size=n**2 /*the size of array. */▼
if (row+col)//2==0 then do;
else do; if row<n
end /*j*/
call show
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: w= max(length(start), length(start
do c=2 for n-1;
end /*c*/; say
▲'''output''' when using the default input of: <tt> 5 </tt>
<pre>
0 1 5 6 14
Line 5,057 ⟶ 5,056:
9 11 17 20 22
10 18 19 23 24
</pre>
{{out|output|text= when using the inputs of: <tt> 5 1 </tt}}
<pre>
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
</pre>
{{out|output|text= when using the inputs of: <tt> 5 -1000 -1 </tt}}
<pre>
-1000 -1001 -1005 -1006 -1014
-1002 -1004 -1007 -1013 -1015
-1003 -1008 -1012 -1016 -1021
-1009 -1011 -1017 -1020 -1022
-1010 -1018 -1019 -1023 -1024
</pre>
|