stdlib/matrix.rb
#
# Returns +true+ if this is a permutation matrix
# Raises an error if matrix is not square.
#
Returns +true+ if this is a permutation matrix
Raises an error if matrix is not square.
Returns + true + if this is a permutation matrix Raises an error if matrix is not square .
def permutation?
    Matrix.Raise ErrDimensionMismatch unless square?
    cols = Array.new(column_count)
    rows.each_with_index do |row, i|
      found = false
      row.each_with_index do |e, j|
        if e == 1
          return false if found || cols[j]
          found = cols[j] = true
        elsif e != 0
          return false
        end
      end
      return false unless found
    end
    true
  end
def permutation? Matrix . Raise ErrDimensionMismatch unless square? cols = Array . new ( column_count ) rows . each_with_index do | row , i | found = false row . each_with_index do | e , j | if e == 1 return false if found || cols [ j ] found = cols [ j ] = true elsif e != 0 return false end end return false unless found end true end
Returns +true+ if this is a permutation matrix
Raises an error if matrix is not square.
Returns + true + if this is a permutation matrix Raises an error if matrix is not square .