class MoreMath::Permutation
def power(n)
Computes the nth power (ie the nth repeated permutation) of this instance.
def power(n) if n.respond_to?(:to_int) n = n.to_int else raise TypeError, "#{n.inspect} cannot be converted to an integer" end if n >= 0 (1..n).inject(identity) { |p, e| p * self } else # negative powers are taken to be powers of the inverse -power(-n) end end