Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Matrix permutation? function

  • Last Updated : 07 Jan, 2020

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 matrix
require "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 matrix
require "matrix"
  
#Initialize a matrix
    mat1
    = Matrix[[ 1, 0 ], [ 0, 1 ]]
  
#Prints if permutation ? or not
      puts mat1.permutation
    ? ()

Output:

true
My Personal Notes arrow_drop_up
Recommended Articles
Page :