Function to create the possible grids
function createGrid ( grid , is1 , N , M ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( is1 ) { grid [ i ] [ j ] = " " ; is1 = false ; } else { grid [ i ] [ j ] = " " ; is1 = true ; } } if ( M % 2 == 0 ) is1 = ! is1 ; } }