def subsets_with_sums_equal(reference_value, array) subsets_with_sums_less_than_or_equal = subsets_with_sum_less_than_or_equal(reference_value, array) subsets_adding_up_to_reference_value = subsets_with_sums_less_than_or_equal.inject([]) do |accumulator, subset| accumulator << subset if subset.inject(0){|sum, value| sum+value} == reference_value accumulator end subsets_adding_up_to_reference