--Apple-Mail-1--94572803
Content-Type: text/plain;
	charsetO-8859-1;
	format­´wed
Content-Transfer-Encoding: quoted-printable

Begin forwarded message:

> From: "Felipe Giotto" <felipegiotto / gmail.com>
> Date: January 28, 2008 1:04:04 PM CST
> To: submission / rubyquiz.com
> Subject: Please Forward - Ruby Quiz Submission
>
> Hi!
>
> This is my first submission, it's a recursive solution. I think it is
> ok, I ran some tests and it worked for all of them. This is a compact
> solution, hope you like it! I also used the Array#sum method,
> unavailable in Ruby stdlibs, to improve readability:
>
> Best regards,
>
> Felipe Luiz ChristˇŠolli Giotto
> Inovare Development Team
> http://www.inovare.net

--Apple-Mail-1--94572803
Content-Disposition: attachment;
	filename
ke_change.rb
Content-Type: application/x-ruby;
	x-unix-mode66;
	nameake_change.rb"
Content-Transfer-Encoding: 7bit

#!/usr/bin/ruby

def make_change(amount, coins  25, 10, 5, 1])
  find_all_possible_changes(amount, coins).sort_by{|item| item.length}.first
end

def find_all_possible_changes(amount, coins)
  possibilities  ]
  unless coins.empty?
    first_coin  oins.shift
    (amount / first_coin).downto 0 do |first_coin_count|
      try  rray.new(first_coin_count){first_coin}
      possibilities + try.sum amount) ? [try] : find_all_possible_changes(amount - (try.sum || 0), coins.dup).collect{|item| try + item}
    end
  end
  possibilities
end




#Refactoring method
class Array
  def sum; inject{|total, item| total + item}; end
end

#Section based on Alexander Stedile's submission: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/288856
if __FILE__ $0
  if ARGV[1]
    coins  RGV[1].split(",").collect{ |coin| coin.to_i }
    puts make_change(ARGV[0].to_i, coins).inspect
  else
    puts make_change(ARGV[0].to_i, coins).inspect
  end
end

--Apple-Mail-1--94572803
Content-Type: text/plain;
	charset-ASCII;
	format­´wed
Content-Transfer-Encoding: 7bit



--Apple-Mail-1--94572803--