From: Ruby Quiz Date: 2008-01-26T00:50:38+09:00 Subject: [QUIZ] Making Change (#154) The three rules of Ruby Quiz: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have passed from the time on this message. 2. Support Ruby Quiz by submitting ideas as often as you can: http://www.rubyquiz.com/ 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= In "Practical Ruby Projects," the author includes a couple of chapters involving coin simulations. These simulators are used to explore the possibilities of replacing a certain coin or adding a new coin. One interesting subproblem of these simulations is that of making change. For example, if we need to give 39 cents change in the United States (where there are 25, 10, 5, and 1 cent pieces), we can give: >> make_change(39) => [25, 10, 1, 1, 1, 1] What if the coins were 10, 7, and 1 cent pieces though and we wanted to make 14 cents change? We would probably want to do: >> make_change(14, [10, 7, 1]) => [7, 7] This week's Ruby Quiz is to complete a change making function with this skeleton: def make_change(amount, coins = [25, 10, 5, 1]) end Your function should always return the optimal change with optimal being the least amount of coins involved. You can assume you have an infinite number of coins to work with.