Skip to content

Instantly share code, notes, and snippets.

@myokoym
Created August 15, 2012 14:44
Show Gist options
  • Save myokoym/3360724 to your computer and use it in GitHub Desktop.
Save myokoym/3360724 to your computer and use it in GitHub Desktop.
ある金額になる硬貨の組み合わせを求める(邪悪流)
#! ruby
sum = 30
coins = [10, 5, 1]
coins.sort.reverse!
count = 0
1.upto(sum) do |n|
count += coins.repeated_combination(n).count {|a| a.inject(:+) == sum }
end
p count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment