Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list_unique_sum_of.py
- t = [100,99,21,1,1,1,2,3,3,7,8,9,10,11,12,-5]
- def list_unique_sum_of(array, n):
- a = []
- x = array[:]
- p = list(set(x))
- x.sort()
- p.sort()
- result = []
- lowest = min(p)
- c = dict((z, x.count(z)+1) for z in p)
- for i in p:
- t = x[:]
- t.pop(0)
- if i < n+1-lowest:
- a.append([i])
- for b in a:
- for j in t:
- k = b+[j]
- k.sort()
- if sum(k) <= n:
- if k not in a:
- v = x[:]
- if k.count(j) < c[j]:
- a.append(k[:])
- if sum(k) == n:
- result.append(k)
- else:
- break
- else:
- break
- else:
- break
- return result
- 0
- ttt = list_unique_sum_of(t,16)
- ttt.sort()
- for z in ttt:
- print(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement