0

this is my work function:

def array_sums_statistics_poss(arr, num):
    if num == 0:
       return True
   elif len(arr) == 0:
       return False
   elif num < 0:
       return False
   else:
       option1 = array_sums_statistics_poss(arr[:-1], num - arr[-1])
       option2 = array_sums_statistics_poss(arr[:-1], num)
       return option1 or option2

I want it to return a list that looks like this [*True/False*, *X*], First element is a bool for if there is a sub-sum list for num, Second element is an int for numbers of calls, 0 if there isn't any!

example: print(array_sums_statistics_poss([7, 6, 18, 20], 14)) ------> [False, 23]

user_3pij
  • 1,334
  • 11
  • 22
  • You may want to look at a decorator to do the counting logic or a profiling library. Or just (_shudder_) use a global variable. – AChampion May 10 '20 at 13:46
  • I don't actually know how to use a global variable, like where should I put it? – Shay Hazan May 10 '20 at 13:53
  • Does this answer your question? [The number of times a function gets called in Python](https://stackoverflow.com/questions/52448773/the-number-of-times-a-function-gets-called-in-python) – ggorlen May 10 '20 at 15:22
  • actually I can't add another function to the problem or use imports, only use global variable, but I have tried to put it in the function and it didn't gave me the right output – Shay Hazan May 10 '20 at 16:35

0 Answers0