Variation in Nim Game | Function to return final grundy Number ( G ) of game ; If pile size is odd ; We XOR pile size + 1 ; If pile size is even ; We XOR pile size - 1 ; Game with 3 piles ; Pile with different sizes ; Function to return result of game ; If G is zero ; If G is non zero
function solve ( p , n ) { let G = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( p [ i ] % 2 != 0 ) G ^= ( p [ i ] + 1 ) ; else G ^= ( p [ i ] - 1 ) ; } return G ; } let n = 3 ; let p = [ 32 , 49 , 58 ] ; let res = solve ( p , n ) ; if ( res == 0 ) document . write ( " " ) ; else document . write ( " " ) ;