Ruby:
def contains?(numbers, n) return true if n == 0 (0...numbers.count).each do |i| right = numbers.drop(i+1) next if right.include? n return true if contains?(numbers.take(i)+right, n-numbers[i]) end false end def solve(numbers) (1..).each do |n| smalls = numbers.select{|i| i <= n} next if smalls.include? n return n if smalls.sum < n return n unless contains?(smalls, n) end end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ruby: