Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

[QUIZ] Making Change (#154)

 
 
Sharon Phillips
Guest
Posts: n/a
 
      01-26-2008
> > make_change 14, [10,7,3]
>
> > my original implementation missed this one


> Why would this fail?


Because my code tried [10, 3] and saw it couldn't make 14
I think my job here is to be the person the rest of you point to and
go 'ha! at least I'm not *that* bad'...



 
Reply With Quote
 
 
 
 
tho_mica_l
Guest
Posts: n/a
 
      01-26-2008
> Is it that hard to call sort()?

Not exactly hard. But since the coin sets in the examples were
ordered, I asked myself if this is intended.

Thomas.
 
Reply With Quote
 
 
 
 
Jens Wille
Guest
Posts: n/a
 
      01-26-2008
James Gray [2008-01-26 04:59]:
> On Jan 25, 2008, at 5:44 PM, Jens Wille wrote:
>> James Gray [2008-01-25 23:57]:
>>> I guess I should have said: is it that hard to call sort {
>>> |a,b| b <=> a }?

>> am i missing something? what's wrong with sort.reverse? apart
>> from the fact that it's a whole lot faster

>
> Because my first computer science teacher drilled into my head
> that you sort it correctly in the first place, instead of using
> two operations to get what you wanted.

well, i guess i have to be glad to be unprejudiced in this regard,
since i don't have any formal CS education

> I guess he hadn't run into Ruby yet.

that's so true! ruby's expressiveness is just amazing. with the
added benefit that the most simple way to do something is almost
always the most efficient one (both in terms of coding speed as well
as execution speed) -- at least from a layman's perspective...

cheers
jens

--
Jens Wille, Dipl.-Bibl. (FH)
prometheus - Das verteilte digitale Bildarchiv für Forschung & Lehre
Kunsthistorisches Institut der Universität zu Köln
Albertus-Magnus-Platz, D-50923 Köln
Tel.: +49 (0)221 470-6668, E-Mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.prometheus-bildarchiv.de/

 
Reply With Quote
 
Dominik Honnef
Guest
Posts: n/a
 
      01-26-2008
On [Sat, 26.01.2008 15:43], Pit Capitain wrote:
> 2008/1/26, Andrew Timberlake <(E-Mail Removed)>:
> > make_change 14, [10, 5, 3] would fail though (...)

>
> => [5, 3, 3, 3]
>
> Regards,
> Pit


I wonder if it would be a big problem, if my script wouldnt handle this case.
It works perfect on the standard cases and (14, [10, 7, 3]) though.
--
Dominik Honnef


 
Reply With Quote
 
tho_mica_l
Guest
Posts: n/a
 
      01-26-2008
> >> I guess I should have said: is it that hard to call sort { |a,b|
> >> b <=> a }?

> > am i missing something? what's wrong with sort.reverse? apart from
> > the fact that it's a whole lot faster

>
> I guess he hadn't run into Ruby yet.


I think reversing an array/list is rather cheap (especially when the
interpreter can use a built-in method coded in C) in comparison to
interpreting a code snippet and performing a comparison for each
element.
 
Reply With Quote
 
Robert Dober
Guest
Posts: n/a
 
      01-26-2008
Stupid me

sort() does not exclude the idiom you have mentioned above.
Funny error of mine.
R.

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

 
Reply With Quote
 
SpringFlowers AutumnMoon
Guest
Posts: n/a
 
      01-26-2008
Sharon Phillips wrote:
>> > make_change 14, [10,7,3]

>>
>> > my original implementation missed this one

>
>> Why would this fail?

>
> Because my code tried [10, 3] and saw it couldn't make 14
> I think my job here is to be the person the rest of you point to and
> go 'ha! at least I'm not *that* bad'...


Are you Pisces, Sharon? Pisces like to make people feel happy.


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
SpringFlowers AutumnMoon
Guest
Posts: n/a
 
      01-26-2008
James Gray wrote:
>> Is it ok to share test cases before the spoiler?

>
> Sure.
>
> James Edward Gray II



seeems like in some weird case:

# make_change(297, [100, 99, 1]) should return [99,99,99]
# make_change(397, [100, 99, 1]) should return [100,99,99,99]
# make_change(497, [100, 99, 1]) should return [100,100,99,99,99]

so there is no rule as to whether 100 or 99 should be used in the first
place.




--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Andrew Timberlake
Guest
Posts: n/a
 
      01-26-2008
> -----Original Message-----
> From: Pit Capitain [mailto(E-Mail Removed)]
> Sent: 26 January 2008 08:44 AM
> To: ruby-talk ML
> Subject: Re: [QUIZ] Making Change (#154)
>
> 2008/1/26, Andrew Timberlake <(E-Mail Removed)>:
> > make_change 14, [10, 5, 3] would fail though (...)

>
> => [5, 3, 3, 3]
>
> Regards,
> Pit


Nice Pit
Next time I'll test before opening my mouth.





 
Reply With Quote
 
Denis Hennessy
Guest
Posts: n/a
 
      01-26-2008
Here's another test case:

make_change 1000001, [1000000, 1] # => [1000000, 1] AND complete in a
reasonable time (avoid brute force searches)

/dh



 
Reply With Quote
 
 
 
Reply

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 ebby83@gmail.com Java 5 01-12-2005 11:10 AM
Data Structure and making the size change dsa89 C++ 3 11-08-2004 06:34 AM



Advertisments