Advertisement
here2share

# b_sum_list_gen.py

Nov 20th, 2021
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. # b_sum_list_gen.py
  2.  
  3. def sum_list_gen(n):
  4.     if n == 2:
  5.         return [1, 1]
  6.     result = []
  7.     ttt = []
  8.     for i in range(n):
  9.             t = [n-i, i]
  10.             result.append(t)
  11.             if i > 1:
  12.                 ttt.append(t)
  13.     while ttt:
  14.         carry = ttt.pop()
  15.         n = carry[-1]
  16.         for i in range(1,n):
  17.             t = carry[:-1]+[n-i, i]
  18.             result.append(t)
  19.             if i > 1:
  20.                 ttt.append(t)
  21.     result.sort()
  22.     return result
  23.  
  24. zzz = sum_list_gen(9)
  25. for z in zzz:
  26.     print z
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement