Advertisement
here2share

# list_unique_sum_of_12.py

Jan 7th, 2021
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # list_unique_sum_of_12.py
  2.  
  3.  
  4. def t12(z):
  5.     L = z
  6.     sss = [[z]]
  7.     ppp = []
  8.     zzz = []
  9.     while 1:
  10.         while len(sss[0]) < L:
  11.             if z > 1:
  12.                 t = sss[0][:-1]+[z-1]
  13.                 if t not in ppp:
  14.                     if sum(t) < L:
  15.                         sss.append(t)
  16.                         ppp.append(t)
  17.             if sum(sss[0])+z > L:
  18.                 z = max(0,z-1)
  19.             else:
  20.                 sss[0].append(z)
  21.         zzz.append(sss.pop(0))
  22.         if sss:
  23.             z = sss[0][-1]
  24.         else:
  25.             break
  26.     zzz.sort(reverse=1)
  27.     return zzz
  28.  
  29. zzz = t12(12)
  30.  
  31. for z in zzz:
  32.     print(z)
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement