Created
January 1, 2015 02:01
-
-
Save meaganewaller/edf9f5fbd35b4f69f79f 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) | |
end | |
def make_change(amount) | |
if amount >= 25 | |
change = amount % 25 | |
@purse[:quarter] = amount/25 | |
make_change(change) | |
elsif amount >= 10 | |
change = amount % 10 | |
@purse[:dime] = amount/10 | |
make_change(change) | |
elsif amount >= 5 | |
@purse[:nickel] = amount/5 | |
make_change(amount - 5) | |
elsif amount > 0 && amount < 5 | |
@purse[:penny] = amount | |
end | |
@purse | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment