Skip to content

Instantly share code, notes, and snippets.

@meaganewaller
Created February 3, 2014 23:43
Show Gist options
  • Save meaganewaller/8794753 to your computer and use it in GitHub Desktop.
Save meaganewaller/8794753 to your computer and use it in GitHub Desktop.
Coin Changer Kata
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