brewersfan1976

different_values.rb

Mar 26th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. def differentValues(a, d)
  2.     array_length = a.length
  3.     x = 0
  4.     y = 1
  5.     difference = 0
  6.    
  7.     while (x < array_length)
  8.         while (y < array_length)
  9.             if (a[x] - a[y]).abs <= d and (a[x] - a[y]).abs > difference then
  10.                 difference = (a[x] - a[y]).abs
  11.             end
  12.                
  13.             y = y + 1
  14.          end
  15.            
  16.          x = x + 1
  17.          y = x + 1
  18.     end
  19.        
  20.     if difference == 0 then
  21.        return -1
  22.     else
  23.        return difference
  24.     end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment