brewersfan1976

different_squares.rb

Mar 4th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.82 KB | None | 0 0
  1. def differentSquares(matrix)
  2.     array = Array.new(10000) {Array.new(4)}
  3.     x = 0
  4.     y = 0
  5.     z = 0
  6.      
  7.     while (x < matrix.length - 1)
  8.           while (y < matrix.length - 1)
  9.                 if matrix[x][y] != nil and matrix[x][y + 1] != nil and
  10.                    matrix[x + 1][y] != nil and
  11.                    matrix[x + 1][y + 1] then
  12.                        
  13.                    array[z][0] = matrix[x][y]
  14.                    array[z][1] = matrix[x][y + 1]
  15.                    array[z][2] = matrix[x + 1][y]
  16.                    array[z][3] = matrix[x + 1][y + 1]
  17.                    z = z + 1
  18.                 end
  19.                    
  20.                 y = y + 1
  21.           end
  22.        
  23.           y = 0
  24.           x = x + 1
  25.     end
  26.    
  27.     array = array.uniq
  28.        
  29.     return array.length - 1
  30.    
  31. end
Advertisement
Add Comment
Please, Sign In to add comment