brewersfan1976

different_squares.rb

Oct 3rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.89 KB | None | 0 0
  1. def differentSquares(matrix)
  2.     x = 0
  3.     y = 0
  4.     z = 0
  5.     square_matrix = Array.new(matrix.length * matrix[0].length) {Array.new(4)}
  6.    
  7.     while(x < square_matrix.length)
  8.         while (y < square_matrix[0].length)
  9.               square_matrix[x][y] = 10
  10.               y = y + 1
  11.         end
  12.        
  13.         x = x + 1
  14.         y = 0
  15.     end
  16.    
  17.     x = 0
  18.     y = 0
  19.    
  20.     while (x < matrix.length - 1)
  21.         while (y < matrix[0].length - 1)
  22.               square_matrix[z][0] = matrix[x][y]
  23.               square_matrix[z][1] = matrix[x][y + 1]
  24.               square_matrix[z][2] = matrix[x + 1][y]
  25.               square_matrix[z][3] = matrix[x + 1][y + 1]
  26.               y = y + 1
  27.               z = z + 1
  28.         end
  29.        
  30.         x = x + 1
  31.         y = 0
  32.     end
  33.    
  34.     square_matrix = square_matrix - [[10, 10, 10, 10]]
  35.    
  36.     return (square_matrix.uniq).length
  37. end
Add Comment
Please, Sign In to add comment