lib/more_math/permutation.rb
# Unrank the rank +m+, that is create a permutation of the appropriate size
# and rank as an array of indices and return it.
Unrank the rank +m+, that is create a permutation of the appropriate size
and rank as an array of indices and return it.
Unrank the rank + m + that is create a permutation of the appropriate size and rank as an array of indices and return it .
def unrank_indices(m)
      result = Array.new(size, 0)
      for i in 0...size
        f = factorial(i)
        x = m % (f * (i + 1))
        m -= x
        x /= f
        result[size - i - 1] = x
        x -= 1
        for j in (size - i)...size
          result[j] += 1 if result[j] > x
        end
      end
      result
    end
def unrank_indices ( m ) result = Array . new ( size , 0 ) for i in 0 ... size f = factorial ( i ) x = m % ( f * ( i + 1 ) ) m -= x x /= f result [ size - i - 1 ] = x x -= 1 for j in ( size - i ) ... size result [ j ] += 1 if result [ j ] > x end end result end
Unrank the rank +m+, that is create a permutation of the appropriate size
and rank as an array of indices and return it.
Unrank the rank + m + that is create a permutation of the appropriate size and rank as an array of indices and return it .
m
<not_specific>