Jump to content

Matrix transposition: Difference between revisions

m
→‎{{header|REXX}}: added/changed some comments and whitespace, used a more idiomatic parsing of the @ array.
m (→‎{{header|REXX}}: added/changed some comments and whitespace, used a more idiomatic parsing of the @ array.)
Line 2,729:
@.=; @.1 = 1.02 2.03 3.04 4.05 5.06 6.07 7.08
@.2 = 111 2222 33333 444444 5555555 66666666 777777777
w=0
do row=1 while @.row\==''
do col row=1 while @.row\==''; parse var @.row A.row.col @.row
end do /*c*/col=1 until @.row==''; parse var @.row A.row.col @.row
end w=max(w, /*r*/ length(A.row.col) ) /*max [↑] build matrix A from matrixwidth for Xelements*/
rows=row-1; cols=col-1 end /*adjustcol*/ for the DO loop indices. /*(used to align ouput).*/
L=0; do j=1 forend rows /*row*/ /* [↑] build matrix A from the @ lists*/
row= row-1 do k=1 /*adjust for cols DO loop index increment.*/
do B.k.j=A.j.k;1 for row /*process each row L=max( L, length(B of the matrix.k.j) )*/
end do /*k*/ =1 for col /* " " column " " " */
end B.k.j= /*A.j*/.k /*transpose the /*A └───matrix is maximum(into width elementB). value*/
do row=1 end while @.row\=='' /*k*/
call showMat 'A',rows,cols
end /*cj*/
call showMat 'B',cols,rows
call showMat 'A', row, col /*display the A matrix to terminal.*/
call showMat 'B', col, row /* " " B " " " */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showMat: arg mat,rows,cols; say; say center( mat 'matrix', (Lw+1)*cols +4, "─")
do r=1 for rows; _= /*newLine*/
do c=1 for cols; _=_ right( value( mat'.'r"."c), Lw) /*append.*/
end /*c*/
say _ /*1 line.*/
end /*r*/; return</lang>
Programming note: &nbsp; the &nbsp; '''showMat''' &nbsp; subroutine could've been written more idiomatically:
<lang rexx>/*──────────────────────────────────────────────────────────────────────────────────────*/
showMat: arg mat,rows,cols; say; say center( mat 'matrix', (L+1)*cols +4, "─")
$=.
do r=1 for rows; _=
do c=1 for cols; _=_ right( value( mat || $ || r || $ || c), L)
end /*c*/
say _
end /*r*/; return</lang>
{{out|output|text=&nbsp; when using the default input:}}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.