Open In App

Ruby | Matrix permutation? function

Last Updated : 30 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads