human
What is a code to minimum cost of purchasing at least X chocolates and the other steps required given the following:
Minimum cost of purchasing at least X chocolates | Function to calculate minimum cost of buying least X chocolates.
Base Case.
Include the i - th box.
Exclude the i - th box.
Return the minimum of the above two cases.
Driver Code.
Given array and value of X.
Store the size of the array.
Print answer"
How can the above be solved in Python?
assistant
#Here is code to minimum cost of purchasing at least X chocolates and the other steps required.
 def findMinCost ( arr , X , n , i = 0 ) :
	if ( X <= 0 ) :
		return 0
	if ( i >= n ) :
		return 10 ** 8
	inc = findMinCost ( arr , X - arr [ i ] [ 0 ] , n , i + 1 )
	if ( inc != 10 ** 8 ) :
		inc += arr [ i ] [ 1 ]
	exc = findMinCost ( arr , X , n , i + 1 )
	return min ( inc , exc )
if __name__ == ' _ _ main _ _ ' :
	arr = [ [ 4 , 3 ] , [ 3 , 2 ] , [ 2 , 4 ] , [ 1 , 3 ] , [ 4 , 2 ] ]
	X = 7
	n = len ( arr )
	ans = findMinCost ( arr , X , n )
	if ( ans != 10 ** 8 ) :
		print ( ans )
	else :
		print ( - 1 )