Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Created August 15, 2012 14:47
Show Gist options
  • Save takaheraw/3360742 to your computer and use it in GitHub Desktop.
Save takaheraw/3360742 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# coding: utf-8
total = 500
coins = [1, 5, 10, 50, 100, 500]
size = total/coins.min
ret = 1.upto(size).inject([]) do |r, n|
comb = coins.repeated_combination(n)
r + comb.select do |c|
c.inject(:+).eql?(total)
end
end
p "pattern = #{ret.compact.sort}"
p "pattern.size = #{ret.size}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment