Created
August 15, 2012 14:44
-
-
Save myokoym/3360724 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
#! 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