Matrix transposition: Difference between revisions

no edit summary
(→‎{{header|jq}}: mention builtin version of transpose)
No edit summary
Line 2,074:
} loop ] {reverse} map
}.</lang>
 
=={{header|PowerShell}}==
{{works with|PowerShell|4.0}}
<lang PowerShell>
function transpose($a) {
if($a.Count -gt 0) {
$n = $a.Count - 1
foreach($i in 0..$n) {
$j = 0
while($j -lt $i) {
$temp = $a[$i][$j]
$a[$i][$j] = $a[$j][$i]
$a[$j][$i] = $temp
$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)
</lang>
<b>Output:</b>
<pre>
2 4 7
3 5 9
4 1 6
 
2 3 4
4 5 1
7 9 6
</pre>
 
=={{header|Prolog}}==
678

edits