I found a solution of a problem and is a recursive function that gives me multiple combinations of numbers like:
- 2 2 3
- 2 4 2
- 2 3 3
- 2 2 4
and I need to find the number of combinations that the functions provides me but the function uses a print to return the values and I cannot find a way to count the number of lines of the output which gives me the solution.
Thanks!
code:
def box_extraction(vec, index, target, reducedNum):
if (reducedNum < 0):
return
if (reducedNum == 0):
for i in range(index):
print(vec[i], end = " ")
print("")
return
prev = 1 if(index == 0) else vec[index - 1]
for k in [2,3,4]:
vec[index] = k
box_extraction(vec, index + 1, target, reducedNum - k)
def findSums(n):
vector = [0] * n
box_extraction(vector, 0, n, n)
n = 8;
findSums(n)