human
Pen Distribution Problem | Recursive function to play Game.
Box is empty , Game Over ! or Both have quit , Game Over !.
P1 moves.
P2 moves.
Increment X.
Switch moves between P1 and P2.
Function to find the number of pens remaining in the box and calculate score for each player.
Score of P1.
Score of P2.
Initialized to zero.
Move = 0 , P1 ' s ▁ turn ▁ ▁ Move ▁ = ▁ 1 , ▁ P2' s turn.
Has P1 quit.
Has P2 quit.
Recursively continue the game.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to pen Distribution Problem and the other steps required.
 def solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 ) :
	if ( N == 0 or ( QuitP1 and QuitP2 ) ) :
		print ( " Number ▁ of ▁ pens ▁ remaining ▁ in ▁ the ▁ box : ▁ " , N )
		print ( " Number ▁ of ▁ pens ▁ collected ▁ by ▁ P1 : ▁ " , P1 )
		print ( " Number ▁ of ▁ pens ▁ collected ▁ by ▁ P2 : ▁ " , P2 )
		return
	if ( Move == 0 and QuitP1 == False ) :
		req_P1 = int ( pow ( 2 , X ) )
		if ( req_P1 <= N ) :
			P1 += req_P1
			N -= req_P1
		else :
			QuitP1 = True
	elif ( Move == 1 and QuitP2 == False ) :
		req_P2 = int ( pow ( 3 , X ) )
		if ( req_P2 <= N ) :
			P2 += req_P2
			N -= req_P2
		else :
			QuitP2 = True
	X += 1
	if ( Move == 1 ) :
		Move = 0
	else :
		Move = 1
	solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 )
def PenGame ( N ) :
	P1 = 0
	P2 = 0
	X = 0
	Move = False
	QuitP1 = False
	QuitP2 = False
	solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 )
N = 22
PenGame ( N )