Advertisement
here2share

# sumCombinations.py

Apr 27th, 2022
1,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.24 KB | None | 0 0
  1. # sumCombinations.py
  2.  
  3. def sumCombinations(n, i, index=0, out=None):
  4.     if not out:
  5.         out=[0]*n
  6.     if n == 0:
  7.         print(out[:index])
  8.     for j in range(i, n+1):
  9.         out[index] = j
  10.         sumCombinations(n-j, j, index+1, out)
  11.  
  12. n = 7
  13. sumCombinations(n, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement