Created
October 25, 2014 00:47
-
-
Save alexluecke/82cc431d5c3b8d563e2f to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
def change(x) | |
solutions = Array.new(x,0) | |
solutions[0] = 0; | |
(0..x).each do |ii| | |
if 1 <= ii && ii < 10 | |
solutions[ii] = 1 + solutions[ii-1] | |
elsif 10 <= ii && ii < 25 | |
solutions[ii] = 1 + [solutions[ii-1], solutions[ii-10]].min | |
elsif 25 <= ii | |
solutions[ii] = 1 + [solutions[ii-1], solutions[ii-10], solutions[ii-25]].min | |
end | |
end | |
return solutions[x] | |
end | |
puts change(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment