brewersfan1976

neighboring_elements.rb

May 26th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.73 KB | None | 0 0
  1. def neighbouringElements(a)
  2.     match = 0
  3.     x_length = a.length
  4.     y_length = a[0].length
  5.     x = 0
  6.     y = 0
  7.    while (x < x_length)
  8.     while (y < y_length - 1)
  9.           if a[x][y] == a[x][y + 1] then
  10.              match = match + 1
  11.           end
  12.              
  13.           y = y + 1
  14.     end
  15.        
  16.           x = x + 1
  17.           y = 0
  18.     end
  19.        
  20.     x = 0
  21.     y = 0
  22.        
  23.     while (y < y_length)
  24.           while (x < x_length - 1)
  25.                 if a[x][y] == a[x + 1][y] then
  26.                     match = match + 1
  27.                 end
  28.                    
  29.                 x = x + 1
  30.           end
  31.              
  32.           x = 0
  33.           y = y + 1
  34.     end
  35.        
  36.     return match
  37.        
  38. end
Advertisement
Add Comment
Please, Sign In to add comment