human
Coin game of two corners ( Greedy Approach ) | Returns optimal value possible that a player can collect from an array of coins of size n . Note than n must be even.
Find sum of odd positioned coins.
Find sum of even positioned coins.
Print even or odd coins depending upon which sum is greater ..
Driver code"
How can the above be solved in Python?
assistant
#Here is code to coin game of two corners ( Greedy Approach ) and the other steps required.
 def printCoins ( arr , n ) :
	oddSum = 0
	for i in range ( 0 , n , 2 ) :
		oddSum += arr [ i ]
	evenSum = 0
	for i in range ( 1 , n , 2 ) :
		evenSum += arr [ i ]
	if oddSum > evenSum :
		start = 0
	else :
		start = 1
	for i in range ( start , n , 2 ) :
		print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr1 = [ 8 , 15 , 3 , 7 ]
	n = len ( arr1 )
	printCoins ( arr1 , n )
	print ( )
	arr2 = [ 2 , 2 , 2 , 2 ]
	n = len ( arr2 )
	printCoins ( arr2 , n )
	print ( )
	arr3 = [ 20 , 30 , 2 , 2 , 2 , 10 ]
	n = len ( arr3 )
	printCoins ( arr3 , n )