[QUIZ] Making Change (#154)

A

Atsuhiro Teshima

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
 
P

Pit Capitain

2008/1/30 said:
(... 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
 
A

Amey Dhoke

[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top