Find an N x N grid whose xor of every row and column is equal | Function to find the n x n matrix that satisfies the given condition ; Initialize x to 0 ; Divide the n x n matrix into n / 4 matrices for each of the n / 4 rows where each matrix is of size 4 x 4 ; Print the generated matrix ; Driver code
function findGrid ( n ) { let arr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = new Array ( n ) ; let x = 0 ; for ( let i = 0 ; i < parseInt ( n / 4 ) ; i ++ ) { for ( let j = 0 ; j < parseInt ( n / 4 ) ; j ++ ) { for ( let k = 0 ; k < 4 ; k ++ ) { for ( let l = 0 ; l < 4 ; l ++ ) { arr [ i * 4 + k ] [ j * 4 + l ] = x ; x ++ ; } } } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { document . write ( arr [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let n = 4 ; findGrid ( n ) ;