Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
44
Task/Matrix-transposition/Picat/matrix-transposition.picat
Normal file
44
Task/Matrix-transposition/Picat/matrix-transposition.picat
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import util.
|
||||
|
||||
go =>
|
||||
M = [[0.0, 0.1, 0.2, 0.3],
|
||||
[0.4, 0.5, 0.6, 0.7],
|
||||
[0.8, 0.9, 1.0, 1.1]],
|
||||
print_matrix(M),
|
||||
|
||||
M2 = [[a,b,c,d,e],
|
||||
[f,g,h,i,j],
|
||||
[k,l,m,n,o],
|
||||
[p,q,r,s,t],
|
||||
[u,v,w,z,y]],
|
||||
print_matrix(M2),
|
||||
|
||||
M3 = make_matrix(1..24,8),
|
||||
print_matrix(M3),
|
||||
nl.
|
||||
|
||||
|
||||
%
|
||||
% Print original matrix and its transpose
|
||||
%
|
||||
print_matrix(M) =>
|
||||
println("Matrix:"),
|
||||
foreach(Row in M) println(Row) end,
|
||||
println("\nTransposed:"),
|
||||
foreach(Row in M.transpose()) println(Row) end,
|
||||
nl.
|
||||
|
||||
%
|
||||
% Make a matrix of list L with Rows rows
|
||||
% (and L.length div Rows columns)
|
||||
%
|
||||
make_matrix(L,Rows) = M =>
|
||||
M = [],
|
||||
Cols = L.length div Rows,
|
||||
foreach(I in 1..Rows)
|
||||
NewRow = new_list(Cols),
|
||||
foreach(J in 1..Cols)
|
||||
NewRow[J] := L[ (I-1)*Cols + J]
|
||||
end,
|
||||
M := M ++ [NewRow]
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue