brewersfan1976

fixed_points_permutation.rb

Aug 3rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.33 KB | None | 0 0
  1. def fixedPointsPermutation(permutation)
  2.     array_new = permutation.sort
  3.     array_length = permutation.length
  4.     x = 0
  5.     sum = 0
  6.    
  7.     while (x < array_length)
  8.           if permutation[x] == array_new[x] then
  9.              sum = sum + 1
  10.           end
  11.            
  12.           x = x + 1
  13.     end
  14.        
  15.     return sum
  16. end
Advertisement
Add Comment
Please, Sign In to add comment