Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A function recursively that takes a list and an int. It would check what combination of numbers on the would result in the lowest number.
A function recursively that takes a list and an int. It would check what combination of numbers on the would result in the lowest number. The numbers in the list can be used multiple times.
For example, helper([1,2,4], 15) would result in 0 because 4 + 4 + 4 + 2 + 1 = 15
Another example is
helper([63, 45, 50, 25, 21], 133)
This would result in 1 because 45 + 45 + 21 + 21 = 132
132 - 131 = 1
This is the body of the function, you can only fill up the missing spaces.
The function takes a list, and an integer. it checks the best combination of elements that would reduce the given integer. Elements in the list can be used multiple times when we subtract them from the given integer. For example, helper([3,4,7,8], 66) would result in 2 because 8+8+8+8+8+8+8+8 = 64
def helper(1st, money): # base case if ...: cur_min = money product = lst[0] tmp = money while ...: return 66-64 = 2
there is no element that is less than 2 so it returns 2.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started