brewersfan1976

permutation_shift.rb

Jun 26th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.44 KB | None | 0 0
  1. def permutationShift(permutation)
  2.     array_length = permutation.length
  3.     x = 0
  4.     max = 0
  5.     min = 0
  6.    
  7.     while (x < array_length)
  8.           difference = permutation[x] - x
  9.        
  10.           if difference > max then
  11.              max = difference
  12.           end
  13.              
  14.           if difference < min then
  15.              min = difference
  16.           end
  17.              
  18.           x = x + 1
  19.     end
  20.  
  21.     return max - min
  22. end
Advertisement
Add Comment
Please, Sign In to add comment