Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed
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
66-64 = 2
there is no element that is less than 2 so it returns 2.
def helper(1st, money): # base case if ...: cur_min = money product = lst[0] tmp = money while ...: return

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

Define Administration?

Answered: 1 week ago

Question

Define Decision making

Answered: 1 week ago