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}
If you liked this kata, check out Part 2.
Mathematics
Algorithms
Similar Kata:
Stats:
Created | May 4, 2014 |
Published | May 4, 2014 |
Warriors Trained | 2916 |
Total Skips | 141 |
Total Code Submissions | 5159 |
Total Times Completed | 1613 |
Ruby Completions | 354 |
JavaScript Completions | 597 |
Elixir Completions | 113 |
Haskell Completions | 24 |
Python Completions | 577 |
Total Stars | 64 |
% of votes with a positive feedback rating | 95% of 326 |
Total "Very Satisfied" Votes | 296 |
Total "Somewhat Satisfied" Votes | 27 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |