Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

A set of coins makes change for n if the sum of the values of the coins is n. For example, if you have 1-cent, 2-cent and 4-cent coins, the following sets make change for 7:

  • 7 1-cent coins
  • 5 1-cent, 1 2-cent coins
  • 3 1-cent, 2 2-cent coins
  • 3 1-cent, 1 4-cent coins
  • 1 1-cent, 3 2-cent coins
  • 1 1-cent, 1 2-cent, 1 4-cent coins

Thus, there are 6 ways to make change for 7. This function count_changetakes a positive integer n and a list of the coin denominations and returns the number of ways to make change for n using these coins (Hint: You will need to use tree recursion):

def count_change(amount, denominations):

  """Returns the number of ways to make change for amount.

  >>> denominations = [50, 25, 10, 5, 1]

  >>> count_change(7, denominations)

  2

  >>> count_change(100, denominations)

  292

  >>> denominations = [16, 8, 4, 2, 1]

  >>> count_change(7, denominations)

  6

  >>> count_change(10, denominations)

  14

  >>> count_change(20, denominations)

  60

  """

  "*** YOUR CODE HERE ***"  

  def count_using(min_coin, amount):

    if amount < 0:

      return 0

    elif amount == 0:

      return 1

    elif min_coin > amount:

      return 0

    else:

      with_min = count_using(min_coin, amount - min_coin)

      without_min = count_using(2*min_coin, amount)

      return with_min + without_min

  return count_using(1, amount)

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93125267
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Systems analysis project personal trainer inc owns and

Systems analysis project Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an international expansion by opening a new "superce ...

Determine the percentage of mass of the atmosphere that

Determine the percentage of mass of the atmosphere that resides between sea level and a height of 18.3 km. Assume an average pressure of 1.00 atm at sea level and a temperature of the atmosphere of 15 °C. The average mol ...

What is the relationship between an interface and a

What is the relationship between an interface and a type? What is the relationship between a class and a type? What is the relationship between a subclass and a type?

We can represent a data set as a collection of object nodes

We can represent a data set as a collection of object nodes and a collection of attribute nodes, where there is a link between each object and each attribute, and where the weight of that link is the value of the object ...

Do you need computers or information and communication

Do you need computers or information and communication technologies to store, organize, and manage data in organizations? Explain how the present day organizations in a developed country like the USA store and manage the ...

Question you are responsible for managing multiple exchange

Question : You are responsible for managing multiple Exchange organizations, and you need to apply identical configurations to servers in all organizations. Since you are just starting out with Exchange Server 2013, and ...

Suppose the following matrix represents the number of saws

Suppose the following matrix represents the number of saws ordered from your company each month over the last year. saws = [1,4,5,3,7,5,3,10,12,8, 7, 4] All the numbers should be zero or positive. (a) Use an if statement ...

C programmingneed help with a c program arrayrearrangec

***C PROGRAMMING*** Need help with a C program array_rearrange.c that rearranges an integer array. The array will be split into two sets of integers one by one. A new array will be created by append the first set to the ...

Uranium vi fluoride is crucial for the enrichment of

Uranium (VI) fluoride is crucial for the enrichment of weapons-grade uranium. If a 1.0 mol sample of helium effuses in 255 s, how many seconds will it take for the same amount of uranium (VI) fluoride to effuse under the ...

A monochromatic source emitting photons at 250 nm shines

A monochromatic source emitting photons at 250 nm shines with equal intensity on a zinc electrode (threshold n =1.04 x1015 Hz) and a sodium electrode (threshold n = 5.51 x1014 Hz). Which of the following statements is tr ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As