brewersfan1976

count_distant_pairs.rb

Dec 22nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.47 KB | None | 0 0
  1. def countDistantPairs(inputString, distance)
  2.     x = 0
  3.     y = 1
  4.     result = 0
  5.      
  6.     while (x < inputString.length)
  7.           while (y < inputString.length)
  8.                 if inputString[x] == inputString[y] and y - x - 1 == distance then
  9.                    result = result + 1
  10.                 end
  11.                    
  12.                 y = y + 1
  13.           end
  14.              
  15.           x = x + 1
  16.           y = x + 1
  17.     end
  18.        
  19.     return result
  20. end
Advertisement
Add Comment
Please, Sign In to add comment