I have been looking at the solution for this problem (below) for hours and cannot figure out how the recursion works. Can someone please explain in basic terms how it works.
Since group is appended and then popped, isn't the popped list going to just always be equal to nothing []?
# Given a list of ints, is it possible to choose a group of some of the
# ints, such that the group sums to the given target?
# 0, 2, 4, 8, 10 -> True
# 0, 2, 4, 8, 14 -> True
# 0, 2, 4, 8, 9 -> False
def sum_checker(ints, total, group, index):
if sum(group) > total: # backtracking
return False
if index == len(ints): # BASE CASE
return sum(group) == total
group.append(ints[index])
if sum_checker(ints, total, group, index + 1):
return True
group.pop()
return sum_checker(ints, total, group, index + 1)
ints = [int(input()) for i in range(int(input()))]
total = int(input())
group = []
print(sum_checker(ints, total, group, 0))