brewersfan1976

matrix_transposition.rb

May 22nd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.47 KB | None | 0 0
  1. def matrixTransposition(matrix)
  2.     x_length = matrix.length
  3.     y_length = matrix[0].length
  4.     x = 0
  5.     y = 0
  6.     a = 0
  7.     b = 0
  8.     array = Array.new(y_length){Array.new(x_length)}
  9.    
  10.     while (y < y_length)
  11.          while (x < x_length)
  12.                array[a][b] = matrix[x][y]
  13.                x = x + 1
  14.                b = b + 1
  15.          end
  16.      
  17.          x = 0
  18.          y = y + 1
  19.          b = 0
  20.          a = a + 1
  21.     end
  22.  
  23.     return array
  24. end
Advertisement
Add Comment
Please, Sign In to add comment