Skip to content

Instantly share code, notes, and snippets.

View kencrocken's full-sized avatar

Ken Crocken kencrocken

View GitHub Profile
@kencrocken
kencrocken / change_maker.rb
Last active August 29, 2015 14:01
How much change do you have?
def make_change(amount, coins = [25,10,5,1])
puts "Input doesn't make sense. You have change leftover." if amount % coins.last != 0
change = {}
coins.each do |coin|
x = amount/coin
amount = amount - (x * coin)
coin_key = coin.to_s
change[coin_key] = x
end
change.each {|k,v| puts "You have #{v}, #{k} cent coin(s)" if v > 0}