📅  最后修改于: 2022-03-11 15:04:49.895000             🧑  作者: Mango
def exact_sum?(sum, arr)
return true if sum==0
return false if sum < 0 || arr.empty?
# now we are checking both cases
exact_sum?(sum - arr[0], arr[1,arr.length]) || exact_sum?(sum, arr[1,arr.length])
end
puts exact_sum?(12, [1, 2, 3, 4, 5]);
# => true