RosettaCodeData/Task/Matrix-transposition/Tailspin/matrix-transposition.tailspin
2023-07-01 13:44:08 -04:00

26 lines
574 B
Text

templates transpose
def a: $;
[1..$a(1)::length -> $a(1..last;$)] !
end transpose
templates printMatrix&{w:}
templates formatN
@: [];
$ -> #
'$@ -> $::length~..$w -> ' ';$@(last..1:-1)...;' !
when <1..> do ..|@: $ mod 10; $ ~/ 10 -> #
end formatN
$... -> '|$(1) -> formatN;$(2..last)... -> ', $ -> formatN;';|
' !
end printMatrix
def m: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]];
'before:
' -> !OUT::write
$m -> printMatrix&{w:2} -> !OUT::write
def mT: $m -> transpose;
'
transposed:
' -> !OUT::write
$mT -> printMatrix&{w:2} -> !OUT::write