brewersfan1976

equidistant_triples.rb

Sep 4th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.60 KB | None | 0 0
  1. def equidistantTriples(coordinates)
  2.     array_length = coordinates.length
  3.     x = 0
  4.     y = 1
  5.     z = 2
  6.     count = 0
  7.    
  8.     while (x < array_length)
  9.         while (y < array_length)
  10.           while (z < array_length)
  11.                 if coordinates[y] == (coordinates[x] + coordinates[z]) / 2.to_f then
  12.                    count = count + 1
  13.                 end
  14.                
  15.                 z = z + 1
  16.           end
  17.              
  18.           y = y + 1
  19.           z = y + 1
  20.         end
  21.            
  22.         x = x + 1
  23.         y = x + 1
  24.         z = y + 1
  25.     end
  26.        
  27.     return count
  28. end
Advertisement
Add Comment
Please, Sign In to add comment