Find the winner in nim | Function to find winner of NIM - game ; case when Alice is winner ; when Bob is winner ; Driver code
def findWinner ( A , n ) : NEW_LINE INDENT res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT res ^= A [ i ] NEW_LINE DEDENT if ( res == 0 or n % 2 == 0 ) : NEW_LINE INDENT return " Alice " NEW_LINE DEDENT else : NEW_LINE INDENT return " Bob " NEW_LINE DEDENT DEDENT A = [ 1 , 4 , 3 , 5 ] NEW_LINE n = len ( A ) NEW_LINE print ( " Winner ▁ = ▁ " , findWinner ( A , n ) ) NEW_LINE