-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathez_combinatorial.py
More file actions
79 lines (65 loc) · 1.47 KB
/
ez_combinatorial.py
File metadata and controls
79 lines (65 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import itertools as it
import math
def gens(A):
counter = 0
sublim = 0
while sublim < len(A):
dv = counter % len(A) + sublim
# print counter % len(A), sublim, dv
counter += 1
if dv == len(A) - 1:
sublim += 1
counter = 0
yield A[dv]
return
def static_vars(**kwargs):
def decorate(func):
for k in kwargs:
setattr(func, k, kwargs[k])
return func
return decorate
#TESTS = ('PM')
TESTS = ('NPM', )
#SET = ['A', 'B', 'C', 'D']
SET = ('A', 'B', 'C', 'D')
# SET = [1, 2, 3, 4]
#SET = (1, 2, 3, 4)
CHN = 2
# 1. permutations
if 'PM' in TESTS:
# A B C D
# 4 4 4 4
# 3 3 3
# 2 2
# 1
print "Permutations (NO REPEAT) count = ", math.factorial(len(SET))
for f in it.permutations(SET, len(SET)):
print f
# 2. selections
if 'SEL' in TESTS:
# A B C D
# 4 4 4 4
# 4 4 4
# 4 4
# 4
print "Selections (REPEAT) count = ", len(SET)**len(SET)
for x in it.product(SET, SET, repeat=2):
print x
# 3. selections N
if 'NSEL' in TESTS:
# A B C D
# 4 4
# 4
print "Selections ', CHN, ' (REPEAT) count = ", len(SET) ** CHN
for x in it.product(SET, repeat=2):
print x
# 4. permutations N
if 'NPM' in TESTS:
# A B C D
# 4 4
# 3
print "Permutations ', CHN,' (NO REPEAT) count = ", math.factorial(len(SET))/math.factorial(len(SET) - CHN)
for f in it.permutations(SET, CHN):
print f
#for f in it.combinations_with_replacement(SET, len(SET)):
# print f