Skip to content

Instantly share code, notes, and snippets.

@alexluecke
Created October 25, 2014 00:47
Show Gist options
  • Save alexluecke/82cc431d5c3b8d563e2f to your computer and use it in GitHub Desktop.
Save alexluecke/82cc431d5c3b8d563e2f to your computer and use it in GitHub Desktop.
#!/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