summaryrefslogtreecommitdiff
path: root/python/problems/recursion/find_sum/find_sum.py
blob: 85f472b721ed10569b310938bf4a40d266698477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def find_sum(xs, gs):
    if gs < 0:
        return False
    if gs == 0:
        return True
    if not xs:
        return False
    return find_sum(xs[1:], gs-xs[0]) or find_sum(xs[1:], gs)

print (find_sum([2,7,3,1,4], 10))
print (find_sum([2,3,2,4], 10))
print (find_sum([], 10))
print (find_sum([1,2,3], 2))
print (find_sum([1,2,3], 7))
print (find_sum([2,7,3,1,4], 9))
print (find_sum([2,7,3,2,4], 17))