Python3 *Use Recursion* Write a function called smallest_sum(A,L) where A is the value and L is a...

50.1K

Verified Solution

Question

Programming

Python3 *Use Recursion*

Write a function called smallest_sum(A,L) where A is the valueand L is a list of ints.

smallest_sum should return the length of the smallestcombinations of L that add up to A

if there are no possible combinations then float(\"inf\") isreturned.

Examples

smallest_sum(5, [2, 3]) == 2

smallest_sum(313, [7, 24, 42]) == 10

smallest_sum(13, [8, 3, 9, 6]) == float(‘‘inf’’)

No Loops and map/reduce functions are allowed

Answer & Explanation Solved by verified expert
4.5 Ratings (877 Votes)
python code with explanation in comments code to copy This recursive function looks for all possible combinations from the list L which can make up to A The parameters curpos represents the current element we are going to add or not add cursum represents the current sum after adding    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students