6 kyu

Making Change

354 of 1,613hencethus

Description:

Making Change

Complete the method that will determine the minimum number of coins needed to make change for a given amount in American currency.

Coins used will be half-dollars, quarters, dimes, nickels, and pennies, worth 50¢, 25¢, 10¢, 5¢ and 1¢, respectively. They'll be represented by the symbols H, Q, D, N and P (symbols in Ruby, strings in in other languages)

The argument passed in will be an integer representing the value in cents. The return value should be a hash/dictionary/object with the symbols as keys, and the numbers of coins as values. Coins that are not used should not be included in the hash. If the argument passed in is 0, then the method should return an empty hash.

Examples

make_change(0)   #-->  {}
make_change(1)   #-->  {:P=>1}
make_change(43)  #-->  {:Q=>1, :D=>1, :N=>1, :P=>3}
make_change(91)  #-->  {:H=>1, :Q=>1, :D=>1, :N=>1, :P=>1}
make_change(0)   #-->  {}
make_change(1)   #-->  {"P":1}
make_change(43)  #-->  {"Q":1, "D":1, "N":1, "P":3}
make_change(91)  #-->  {"H":1, "Q":1, "D":1, "N":1, "P":1}
makeChange(0)   //-->  {}
makeChange(1)   //-->  {"P":1}
makeChange(43)  //-->  {"Q":1, "D":1, "N":1, "P":3}
makeChange(91)  //-->  {"H":1, "Q":1, "D":1, "N":1, "P":1}
Currency.make_change(0)   #-->  %{}
Currency.make_change(1)   #-->  %{:P=>1}
Currency.make_change(43)  #-->  %{:Q=>1, :D=>1, :N=>1, :P=>3}
Currency.make_change(91)  #-->  %{:H=>1, :Q=>1, :D=>1, :N=>1, :P=>1}

If you liked this kata, check out Part 2.

Mathematics
Algorithms

Stats:

CreatedMay 4, 2014
PublishedMay 4, 2014
Warriors Trained2916
Total Skips141
Total Code Submissions5159
Total Times Completed1613
Ruby Completions354
JavaScript Completions597
Elixir Completions113
Haskell Completions24
Python Completions577
Total Stars64
% of votes with a positive feedback rating95% of 326
Total "Very Satisfied" Votes296
Total "Somewhat Satisfied" Votes27
Total "Not Satisfied" Votes3
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • hencethus Avatar
  • jhoffner Avatar
  • Unnamed Avatar
  • anter69 Avatar
  • Voile Avatar
  • cliffstamp Avatar
Ad