Variation in Nim Game | Function to return final grundy Number ( G ) of game ; if pile size is odd ; We XOR pile size + 1 ; We XOR pile size - 1 ; Game with 3 piles ; pile with different sizes ; Function to return result of game ; if ( $res == 0 ) if G is zero ; else if G is non zero
< ? php function solve ( $ p , $ n ) { $ G = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ p [ $ i ] & 1 ) $ G ^= ( $ p [ $ i ] + 1 ) ; $ G ^= ( $ p [ $ i ] - 1 ) ; } return $ G ; } $ n = 3 ; $ p = array ( 32 , 49 , 58 ) ; $ res = solve ( $ p , $ n ) ; echo " Player ▁ 2 ▁ wins " ; echo " Player ▁ 1 ▁ wins " ; ? >