Transpose an arbitrarily sized rectangular Matrix.




 
bundle Default {
  class Transpose {
    function : Main(args : String[]) ~ Nil {
      input := [[1, 1, 1, 1]
        [2, 4, 8, 16]
        [3, 9, 27, 81]
        [4, 16, 64, 256]
        [5, 25, 125, 625]];
      dim := input->Size();
 
      output := Int->New[dim[0],dim[1]];
      for(i := 0; i < dim[0]; i+=1;) {
        for(j := 0; j < dim[1]; j+=1;) {
          output[i,j] := input[i,j];
        };
      };
 
      Print(output);
    }
 
    function : Print(matrix : Int[,]) ~ Nil {
      dim := matrix->Size();
      for(i := 0; i < dim[0]; i+=1;) {
        for(j := 0; j < dim[1]; j+=1;) {
          IO.Console->Print(matrix[i,j])->Print('\t');
        };
        '\n'->Print();
      };
    }
  }
}
 