human
Coin game winner where every player has three choices | To find winner of game.
To store results.
Initial values.
Computing other values ..
If A losses any of i - 1 or i - x or i - y game then he will definitely win game i.
Else A loses game ..
If dp [ n ] is true then A will game otherwise he losses.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to coin game winner where every player has three choices and the other steps required.
 def findWinner ( x , y , n ) :
	dp = [ 0 for i in range ( n + 1 ) ]
	dp [ 0 ] = False
	dp [ 1 ] = True
	for i in range ( 2 , n + 1 ) :
		if ( i - 1 >= 0 and not dp [ i - 1 ] ) :
			dp [ i ] = True
		elif ( i - x >= 0 and not dp [ i - x ] ) :
			dp [ i ] = True
		elif ( i - y >= 0 and not dp [ i - y ] ) :
			dp [ i ] = True
		else :
			dp [ i ] = False
	return dp [ n ]
x = 3 ; y = 4 ; n = 5
if ( findWinner ( x , y , n ) ) :
	print ( ' A ' )
else :
	print ( ' B ' )