class MoreMath::Permutation
def rank_indices(p)
Rank the indices of the permutation +p+. Beware that this method may
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