What you want is not permutations, but product. Also, I interpret restrictions as:
- C and F cannot be false
- If A is false, E and G cannot be false
- If B is false, D cannot be false
With that, the code is as followed:
import pprint
from itertools import product
def myproduct():
keys = 'abcdefg'
values = [(0, 1) for k in keys]
for value in product(*values):
d = dict(zip(keys, value))
# Skip: C and F that are 0 (False)
if d['c'] == 0 or d['f'] == 0:
continue
# Skip: When A is false, E and G cannot be false
if d['a'] == 0 and (d['e'] == 0 or d['g'] == 0):
continue
# Skip: When B is false, D cannot be false
if d['b'] == 0 and d['d'] == 0:
continue
yield d # This 'permutation' is good
for d in myproduct():
pprint.pprint(d)
Output:
{'a': 0, 'b': 0, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1}
{'a': 0, 'b': 1, 'c': 1, 'd': 0, 'e': 1, 'f': 1, 'g': 1}
{'a': 0, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1}
{'a': 1, 'b': 0, 'c': 1, 'd': 1, 'e': 0, 'f': 1, 'g': 0}
{'a': 1, 'b': 0, 'c': 1, 'd': 1, 'e': 0, 'f': 1, 'g': 1}
{'a': 1, 'b': 0, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 0}
{'a': 1, 'b': 0, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1}
{'a': 1, 'b': 1, 'c': 1, 'd': 0, 'e': 0, 'f': 1, 'g': 0}
{'a': 1, 'b': 1, 'c': 1, 'd': 0, 'e': 0, 'f': 1, 'g': 1}
{'a': 1, 'b': 1, 'c': 1, 'd': 0, 'e': 1, 'f': 1, 'g': 0}
{'a': 1, 'b': 1, 'c': 1, 'd': 0, 'e': 1, 'f': 1, 'g': 1}
{'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 0, 'f': 1, 'g': 0}
{'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 0, 'f': 1, 'g': 1}
{'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 0}
{'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1}
Notes:
values
is a list of (0, 1)
:
[(0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1)]
Each value
is a tuple of 7 numbers such as:
(1, 1, 1, 0, 0, 1, 0)
d
is a dictionary in which the keys are a, b, ... and the values are 0 and 1