brewersfan1976

largest_distance.rb

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