Course of Raku / Addendum 🆕 / Working with data / Lists, arrays, and hashes / Exercises / Transpose a matrix
Solution: Transpose a matrix
Here is a possible solution to the task.
Code
my @matrix = [1, 2, 3], [4, 5, 6];
say [Z] @matrix;🦋 You can find the source code in the file transpose.raku.
Output
((1 4) (2 5) (3 6))Comments
- The zip metaoperator
Zpairs up elements by position. Used as a reduction[Z], it zips all the rows together, turning columns into rows — exactly a transpose.