Advertisement
here2share

# list_unique_sum_of.py

Jan 28th, 2020
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # list_unique_sum_of.py
  2.  
  3. t = [100,99,21,1,1,1,2,3,3,7,8,9,10,11,12,-5]
  4.  
  5. def list_unique_sum_of(array, n):
  6.     a = []
  7.     x = array[:]
  8.     p = list(set(x))
  9.     x.sort()
  10.     p.sort()
  11.     result = []
  12.     lowest = min(p)
  13.     c = dict((z, x.count(z)+1) for z in p)
  14.     for i in p:
  15.         t = x[:]
  16.         t.pop(0)
  17.         if i < n+1-lowest:
  18.             a.append([i])
  19.             for b in a:
  20.                 for j in t:
  21.                     k = b+[j]
  22.                     k.sort()
  23.                     if sum(k) <= n:
  24.                         if k not in a:
  25.                             v = x[:]
  26.                             if k.count(j) < c[j]:
  27.                                 a.append(k[:])
  28.                                 if sum(k) == n:
  29.                                     result.append(k)
  30.                             else:
  31.                                 break
  32.                     else:
  33.                         break
  34.         else:
  35.             break
  36.     return result
  37. 0
  38. ttt = list_unique_sum_of(t,16)
  39.  
  40. ttt.sort()
  41. for z in ttt:
  42.     print(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement