Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [QUIZ] Making Change (#154)

Thread Tools

[QUIZ] Making Change (#154)

Atsuhiro Teshima
Posts: n/a
Jesús Gabriel y Galán wrote:

Hi Gesús, Thank for your advices!

> The first problem is that your solution returns
> [10,1,1,1,1] for make_change(14, [10,7,1])
> when the correct answer would be [7,7].

Now,I'm trying to fix this problem.

> To avoid iterating so much, check at Ilan Berci solution.
> For each coin value, making a division you would know
> how many of this coins can fit, something like (not tested):
> num = amount / coin
> num.times {change << coin}
> amount %= coin

Oh, obviously this code is better than mine.I'll fix it.

Atsuhiro Teshima
Posted via

Reply With Quote
Pit Capitain
Posts: n/a
2008/1/30, Raffa <(E-Mail Removed)>:
> (... interesting post ...)

Raffa, I think your algorithm doesn't always find the best solution. Try it with

make_change(24, [10, 7, 1])

What would be the answer of your algorithm? I think it would be one of

2*10 + 4*1
3*7 + 3*3

but not

1*10 + 2*7


Reply With Quote
Amey Dhoke
Posts: n/a
[Note: parts of this message were removed to make it a legal post.]


I joined Ruby Talk couple of days before and this is my first post.
I am a newbie and tring to learn Ruby from last one month.

I have written spec for the problem (This is the first time I am playing
with RSpec) -

And this is my (naive ) solution -

Solving this first problem was fun. I learned a lot from everyone's


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a small change to a large XML document Dan Stromberg Python 3 09-25-2007 06:59 AM
A Paradise DNS address change? What change? There was no change. Tony Neville NZ Computing 7 09-22-2006 01:02 PM
Re: A fresh new approach to making making online Fakename Computer Information 0 11-18-2005 02:10 AM
Making new Flavors : Making a custom transferhandler for and drop applications Java 5 01-12-2005 11:10 AM
Data Structure and making the size change dsa89 C++ 3 11-08-2004 06:34 AM