Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list_combos_sum_of_12.py
- def t12(z):
- L = z
- sss = [[z]]
- ppp = []
- zzz = []
- while 1:
- while len(sss[0]) < L:
- if z > 1:
- t = sss[0][:-1]+[z-1]
- if t not in ppp:
- if sum(t) < L:
- sss.append(t)
- ppp.append(t)
- if sum(sss[0])+z > L:
- z = max(0,z-1)
- else:
- sss[0].append(z)
- zzz.append(sss.pop(0))
- if sss:
- z = sss[0][-1]
- else:
- break
- return zzz
- combos = t12(12)
- def permute_unique(nums):
- perms = [[]]
- for n in nums:
- new_perm = []
- for perm in perms:
- for i in range(len(perm) + 1):
- new_perm.append(perm[:i] + [n] + perm[i:])
- # handle duplication
- if i < len(perm) and perm[i] == n: # skips a few
- break
- perms = new_perm
- return perms
- zzz = sum([[z for z in permute_unique(combo)] for combo in combos],[])
- zzz.sort(reverse=0)
- L = len(zzz)
- for z in zzz:
- print z,L
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement