Number range is: 1 to 100
I wish to print out every unique combination between 1 and 100 whose sum equals 100 and finally a count of such combinations For example:
[1,99]
[1,2,97]
[1,2,3,4,5,85]
So, I need two things:
- print each valid combination
- return a final count of the number of such combinations
Here is what I have tried so far with no success:
count = 0
def get_count(target, data_range, current_sum):
global count
for num in data_range:
current_sum += num
if current_sum > target:
break
elif current_sum == target:
count += 1
current_sum = 0
elif current_sum < target:
get_count(target, range(num + 1, 101), current_sum)
return count
get_count(target = 100, data_range = range(1,101), current_sum = 0)