Ruby | Matrix permutation? function
The permutation?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a permutation matrix, else it returns false. It returns error if anything other than square matrix is used.
Syntax: mat1.permutation?()
Parameters: The function needs the matrix to be checked for permutation matrix or not.
Return Value: It returns true if it is a permutationl matrix, else it returns false.
Example 1:
#Ruby program for permutation ? () method in Matrix #Include matrixrequire "matrix" #Initialize a matrix mat1 = Matrix[[ 1, 21 ], [ 31, 18 ]] #Prints if permutation ? or not puts mat1.permutation ? () |
Output:
false
Example 2:
#Ruby program for permutation ? () method in Matrix #Include matrixrequire "matrix" #Initialize a matrix mat1 = Matrix[[ 1, 0 ], [ 0, 1 ]] #Prints if permutation ? or not puts mat1.permutation ? () |
Output:
true


