#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Matrix_transposition
#

func transpose(matrix) {
    matrix[0].range.map{|i| matrix.map{_[i]}};
};
 
var m = [
  [1,  1,   1,   1],
  [2,  4,   8,  16],
  [3,  9,  27,  81],
  [4, 16,  64, 256],
  [5, 25, 125, 625],
];
 
transpose(m).each { |row|
    "%5d" * row.len -> printlnf(row...);
}
