Ruby | Matrix permutation? function
Last Updated :
30 Nov, 2022
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 permutation matrix, else it returns false.
Example 1:
CPP
#Ruby program for permutation ? () method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 21 ], [ 31, 18 ]]
#Prints if permutation ? or not
puts mat1.permutation
? ()
|
Output:
false
Example 2:
CPP
#Ruby program for permutation ? () method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 0 ], [ 0, 1 ]]
#Prints if permutation ? or not
puts mat1.permutation
? ()
|
Output:
true
Share your thoughts in the comments
Please Login to comment...