Skip to content

Instantly share code, notes, and snippets.

@skandhas
Created March 1, 2012 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skandhas/1948550 to your computer and use it in GitHub Desktop.
Save skandhas/1948550 to your computer and use it in GitHub Desktop.
class Sumify
def self.run(num, collection)
collection.size.times.map { |n| collection.combination(n).to_a }.flatten(1).select { |c| c.inject(:+) == num }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment