Matrix transposition: Difference between revisions

Added solution for Action!
(Added solution for Action!)
Line 81:
(cons-each (first xss)
(transpose-list (rest xss)))))</lang>
 
=={{header|Action!}}==
<lang Action!>DEFINE PTR="CARD"
 
TYPE Matrix=[
BYTE width,height
PTR data] ;BYTE ARRAY
 
PROC PrintB2(BYTE b)
IF b<10 THEN Put(32) FI
PrintB(b)
RETURN
 
PROC PrintMatrix(Matrix POINTER m)
BYTE i,j
BYTE ARRAY d
 
d=m.data
FOR j=0 TO m.height-1
DO
FOR i=0 TO m.width-1
DO
PrintB2(d(j*m.width+i)) Put(32)
OD
PutE()
OD
RETURN
 
PROC Create(MATRIX POINTER m BYTE w,h BYTE ARRAY a)
m.width=w
m.height=h
m.data=a
RETURN
 
PROC Transpose(Matrix POINTER in,out)
BYTE i,j
BYTE ARRAY din,dout
 
din=in.data
dout=out.data
out.width=in.height
out.height=in.width
FOR j=0 TO in.height-1
DO
FOR i=0 TO in.width-1
DO
dout(i*out.width+j)=din(j*in.width+i)
OD
OD
RETURN
 
PROC Main()
MATRIX in,out
BYTE ARRAY din(35),dout(35)
BYTE i
 
FOR i=0 TO 34
DO
din(i)=i
OD
Create(in,7,5,din)
Create(out,0,0,dout)
Transpose(in,out)
 
PrintE("Input:")
PrintMatrix(in)
PutE() PrintE("Transpose:")
PrintMatrix(out)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Matrix_transposition.png Screenshot from Atari 8-bit computer]
<pre>
Input:
0 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
 
Transpose:
0 7 14 21 28
1 8 15 22 29
2 9 16 23 30
3 10 17 24 31
4 11 18 25 32
5 12 19 26 33
6 13 20 27 34
</pre>
 
=={{header|ActionScript}}==
Anonymous user