Created
February 3, 2014 23:43
-
-
Save meaganewaller/8794753 to your computer and use it in GitHub Desktop.
Coin Changer Kata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CoinChanger | |
def initialize | |
@purse = Hash.new(0) | |
@coin_values = { :quarter => 25, :dime => 10, :nickel => 5, :penny => 1} | |
end | |
def make_change(amount) | |
@coin_values.each_value do |value| | |
if amount >= value | |
coin = @coin_values.invert[value] | |
@purse[coin] = amount/value | |
amount %= value | |
end | |
end | |
@purse | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment