Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Fwd: Please Forward: Ruby Quiz Submission
James Gray
1/31/2008 4:13:00 AM
[Note: parts of this message were removed to make it a legal post.]
Begin forwarded message:
> From: James Bracy <waratuman86@gmail.com>
> Date: January 30, 2008 8:14:12 PM CST
> To: submission@rubyquiz.com
> Subject: Please Forward: Ruby Quiz Submission
>
> Here is the url to my blog with the code posted. This is my first
> post, still learning how things are done on ruby quiz.
>
>
http://waratuman86.com/articles/2008/01/30/ruby-quiz-mak...
>
> And here is the code. It is incomplete, but I have stated and
> example on the site and how in theory it should work.
>
> Basically the code starts with the small coin amount and works it's
> way up trying to use the bigger coins instead of the smaller.
>
> Thanks,
>
> James
>
> def make_change(amount, coins=[25,10,5,1], change={})
> coins.sort!
> puts change
> return change if coins.empty?
>
> if change.empty?
> change[coins.first] = amount / coins.first
> amount -= coins.first * change[coins.first]
> else
> change.each_pair do |k, count|
> change_count = count_change(change)
> if (amount+change_count) % coins.first == 0
> change[coins.first] = (amount+change_count) / coins.first
> change[k] = (change_count + amount -
> change[coins.first]*coins.first) / k
> amount -= change[coins.first] - change[k]
> else
> change[coins.first] = 0
> end
> end
> end
>
> make_change(amount, coins-change.keys, change)
> end
>
> def count_change(change={})
> total = 0
> change.each_pair do |coin, count|
> total += coin * count
> end
> total
> end
>
> James R. Bracy: LeTourneau University, Computer Science and
> Engineering
> contact | jamesbracy@letu.edu - 315.935.0302
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Fwd: Please Forward: Ruby Quiz Submission
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password