/*********************************************************** transpose.pi from Constraint Solving and Planning with Picat, Springer by Neng-Fa Zhou, Hakan Kjellerstrand, and Jonathan Fruhman ***********************************************************/ main => % sample matrix Matrix = {{1,2,3},{4,5,6}}, N = length(Matrix), M = length(Matrix[1]), Transposed = new_array(M,N), % transposes the matrix foreach (I in 1..N, J in 1..M) Transposed[J,I] = Matrix[I,J] end, % prints the transposed matrix foreach (Row in Transposed) println(Row) end.