Check if matrix A can be converted to B by changing parity of corner elements of any submatrix | PHP 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
< ? php $ N = 3 ; $ M = 3 ; function check ( $ a , $ b ) { for ( $ i = 1 ; $ i < $ GLOBALS [ ' N ' ] ; $ i ++ ) { for ( $ j = 1 ; $ j < $ GLOBALS [ ' 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 < $ GLOBALS [ ' N ' ] ; $ i ++ ) { for ( $ j = 0 ; $ j < $ GLOBALS [ ' M ' ] ; $ j ++ ) { if ( $ a [ $ i ] [ $ j ] != $ b [ $ i ] [ $ j ] ) return false ; } } return true ; } $ a = array ( array ( 0 , 1 , 0 ) , array ( 0 , 1 , 0 ) , array ( 1 , 0 , 0 ) ) ; $ b = array ( array ( 1 , 0 , 0 ) , array ( 1 , 0 , 0 ) , array ( 1 , 0 , 0 ) ) ; if ( check ( $ a , $ b ) ) echo " Yes " ; else echo " No " ; ? >