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

# [QUIZ] Making Change (#154)

Atsuhiro Teshima
Guest
Posts: n/a

 01-30-2008
Jesús Gabriel y Galán wrote:

> 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 http://www.ruby-forum.com/.

Pit Capitain
Guest
Posts: n/a

 01-31-2008
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

Regards,
Pit

Amey Dhoke
Guest
Posts: n/a

 01-31-2008
[Note: parts of this message were removed to make it a legal post.]

Hi,

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) - http://pastie.caboo.se/145869

And this is my (naive ) solution - http://pastie.caboo.se/145888

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

Cheers,
Amey

 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 OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Dan Stromberg Python 3 09-25-2007 06:59 AM Tony Neville NZ Computing 7 09-22-2006 01:02 PM Fakename Computer Information 0 11-18-2005 02:10 AM ebby83@gmail.com Java 5 01-12-2005 11:10 AM dsa89 C++ 3 11-08-2004 06:34 AM