tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
15
Task/Ordered-Partitions/Python/ordered-partitions-1.py
Normal file
15
Task/Ordered-Partitions/Python/ordered-partitions-1.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from itertools import combinations
|
||||
|
||||
def partitions(*args):
|
||||
def p(s, *args):
|
||||
if not args: return [[]]
|
||||
res = []
|
||||
for c in combinations(s, args[0]):
|
||||
s0 = [x for x in s if x not in c]
|
||||
for r in p(s0, *args[1:]):
|
||||
res.append([c] + r)
|
||||
return res
|
||||
s = range(sum(args))
|
||||
return p(s, *args)
|
||||
|
||||
print partitions(2, 0, 2)
|
||||
10
Task/Ordered-Partitions/Python/ordered-partitions-2.py
Normal file
10
Task/Ordered-Partitions/Python/ordered-partitions-2.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from itertools import combinations as comb
|
||||
|
||||
def partitions(*args):
|
||||
def minus(s1, s2): return [x for x in s1 if x not in s2]
|
||||
def p(s, *args):
|
||||
if not args: return [[]]
|
||||
return [[c] + r for c in comb(s, args[0]) for r in p(minus(s, c), *args[1:])]
|
||||
return p(range(1, sum(args) + 1), *args)
|
||||
|
||||
print partitions(2, 0, 2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue