RosettaCodeData/Task/Matrix-transposition/PowerShell/matrix-transposition.psh

24 lines
478 B
Plaintext

function transpose($a) {
if($a.Count -gt 0) {
$n = $a.Count - 1
foreach($i in 0..$n) {
$j = 0
while($j -lt $i) {
$a[$i][$j], $a[$j][$i] = $a[$j][$i], $a[$i][$j]
$j++
}
}
}
$a
}
function show($a) {
if($a.Count -gt 0) {
$n = $a.Count - 1
0..$n | foreach{ "$($a[$_][0..$n])" }
}
}
$a = @(@(2, 4, 7),@(3, 5, 9),@(4, 1, 6))
show $a
""
show (transpose $a)