Check if matrix A can be converted to B by changing parity of corner elements of any submatrix | javascript implementation of the above approach ; Boolean function that returns true or false ; Traverse for all elements ; If both are not equal ; Change the parity of all corner elements ; Check if A is equal to B ; Not equal ; First binary matrix ; Second binary matrix
var N = 3 , M = 3 ; function check ( a , b ) { for ( i = 1 ; i < N ; i ++ ) { for ( j = 1 ; j < M ; j ++ ) { if ( a [ i ] [ j ] != b [ i ] [ j ] ) { a [ i ] [ j ] ^= 1 ; a [ 0 ] [ 0 ] ^= 1 ; a [ 0 ] [ j ] ^= 1 ; a [ i ] [ 0 ] ^= 1 ; } } } for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < M ; j ++ ) { if ( a [ i ] [ j ] != b [ i ] [ j ] ) return false ; } } return true ; } var a = [ [ 0 , 1 , 0 ] , [ 0 , 1 , 0 ] , [ 1 , 0 , 0 ] ] ; var b = [ [ 1 , 0 , 0 ] , [ 1 , 0 , 0 ] , [ 1 , 0 , 0 ] ] ; if ( check ( a , b ) ) document . write ( " " ) ; else document . write ( " " ) ;