Assuming a simplified football scoring system where you can score {2, 3, 7} points, what are all the possible ways that you can score given a number of points?
I'm just working problems in the EPI book, and he solves this problem using DP. I wanted to practice a recursive technique, but I'm getting tripped up trying to save all the different ways in to a results list.
def find_scoring(points, scores):
ways_to_score = [2, 3, 7]
def score_finder(p, scores):
print(scores, p)
if p == 0:
print('here')
results.append(scores)
return True
elif p <= 1:
return False
for i in ways_to_score:
scores.append(i)
if not score_finder(p-i, scores):
scores.pop()
return False
results = []
score_finder(points, scores)
return results
print(find_scoring(12, []))
For the above, I would expect to see [[2,2,2,2,2,2], [2,2,2,3,3], ....]
I cannot figure out how to pass the scores variable properly. Appreciate the assist!