Advertisement
brewersfan1976

construct_submatrix.rb

Mar 11th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.98 KB | None | 0 0
  1. def constructSubmatrix(matrix, rowsToDelete, columnsToDelete)
  2.     x = 0
  3.    
  4.     while (x < rowsToDelete.length)
  5.           matrix.delete_at(rowsToDelete[x])
  6.        
  7.           y = x + 1
  8.        
  9.           while (y < rowsToDelete.length)
  10.                 rowsToDelete[y] = rowsToDelete[y] - 1
  11.                 y = y + 1
  12.           end
  13.        
  14.           x = x + 1
  15.     end
  16.    
  17.     x = 0
  18.     y = 0
  19.    
  20.     while (x < matrix.length)
  21.           temp_column = Array.new
  22.           temp_column = columnsToDelete.clone
  23.          
  24.           while (y < temp_column.length)
  25.                 matrix[x].delete_at(temp_column[y])
  26.              
  27.                 z = y + 1
  28.              
  29.                 while (z < temp_column.length)
  30.                       temp_column[z] = temp_column[z] - 1
  31.                       z = z + 1
  32.                 end
  33.                
  34.                 y = y + 1
  35.           end
  36.          
  37.           x = x + 1
  38.           y = 0
  39.     end
  40.      
  41.     return matrix
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement