class MoreMath::Permutation
def cycles
perm.cycles
# => #
perm = Permutation.new(7, 23)
Example:
new Permutation instance with the Permutation.from_cycles method.
The return value of this method can be used to create a
Returns the cycles representation of this Permutation instance.
def cycles perm = value result = [[]] seen = {} current = nil loop do current or current = perm.find { |x| !seen[x] } break unless current if seen[current] current = nil result << [] else seen[current] = true result[-1] << current current = perm[current] end end result.pop result.select { |c| c.size > 1 }.map do |c| min_index = c.index(c.min) c[min_index..-1] + c[0...min_index] end end