lib/more_math/permutation.rb
# Rank the indices of the permutation +p+. Beware that this method may
# change its argument +p+.
Rank the indices of the permutation +p+. Beware that this method may
change its argument +p+.
Rank the indices of the permutation + p + . Beware that this method may change its argument + p + .
def rank_indices(p)
      result = 0
      for i in 0...size
        result += p[i] * factorial(size - i - 1)
        for j in (i + 1)...size
          p[j] -= 1 if p[j] > p[i]
        end
      end
      result
    end
def rank_indices ( p ) result = 0 for i in 0 ... size result += p [ i ] * factorial ( size - i - 1 ) for j in ( i + 1 ) ... size p [ j ] -= 1 if p [ j ] > p [ i ] end end result end
Rank the indices of the permutation +p+.
Rank the indices of the permutation + p + .
p
<not_specific>