@mearnest/

CNF DNF converter

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from itertools import product

def lock_problem_solution(*words):
  """
    Given a list of strings, where the characters represent the 
    identities of people, and each string is a group of people
    who should be able to open lock,
    returns a list a list of strings representing the people
    who should be given the keys to a set of locks,
    such that the group can only all the locks iff they contain
    one of the given subgroups.
  """
  clauses = [set(word) for word in product(*words)]
  not_redundant = lambda w: not any([v < w for v in clauses])
  minimal_clauses = filter(not_redundant, clauses)
  formatted = [''.join(sorted(list(s))) for s in minimal_clauses]
  return sorted(list(set(formatted)))

for (i,s) in enumerate(lock_problem_solution('AB','ACD','BDE')):
  print('    Lock',str(i+1)+': ',s)