Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8612255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:34:54+00:00 2026-06-12T04:34:54+00:00

I am doing the coin-change problem. I have finished the problem in that it

  • 0

I am doing the coin-change problem. I have finished the problem in that it prints out how many coins I need to make the least amount of change possible, but how do I change my program so that it also prints those coins??

Here is a sample I/O:

input: coin_change(48, [1, 5, 10, 25, 50])

output: [6, [25, 10, 10, 1, 1, 1]]

Currently my code only returns the 6.

by the way, this must be done with recursion only. no loops are allowed

Code:

def change(C, V):
    def min_coins(i, aC):
        if aC == 0:
            return 0
        elif i == -1 or aC < 0:
            return float('inf')
        else:
            return min(min_coins(i-1, aC), 1 + min_coins(i, aC-V[i]))
    return min_coins(len(V)-1, C)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:34:55+00:00Added an answer on June 12, 2026 at 4:34 am

    A different version of your program:

    def change(C, V, res=None):
        res = [] if res is None else res
        if len(V) == 0:
            return len(res), res
        maxx = max(V)
        V.remove(maxx)
        ans = C//maxx
        if ans == 0 and maxx < C :
            res += [maxx] * ans
            return len(res), res
        else:
            res += [maxx] * ans
            return  change(C % maxx, V, res)
    
    print change(48,[1, 5, 10, 25, 50])
    print change(30,[25, 10, 2, 3, 1])
    

    output:

    (6, [25, 10, 10, 1, 1, 1])
    (3, [25, 3, 2])
    

    PS: I’ll add an explanation if you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a loop for a coin flipping program that I'm making. the problem
Doing a small project I have received some Java code that I should rewrite
I am doing a simple coin flipping experiment for class that involves flipping a
Doing a custom Tumblr theme that will have a mix of the usual Tumblr
I wrote a simple coin change algorithm that currently finds the minimum number of
Im doing something like this to get a list of all users that have
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
Doing some jquery animation. I have certain divs set up with an attribute of
Doing a search using django-sphinx gives me results._sphinx that says there were 68 results,
Doing a some practice questions for exam tomorrow can't figure out this one What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.