SHARE
TWEET

function did not work correctly

a guest Jun 30th, 2010 63 Never
  1. token_list = ['a', 'b', 'c']
  2.  
  3. contradictions = {
  4.     'a': set(['b']),
  5.     'b': set(['a']),
  6.     'c': set()
  7. }
  8.  
  9. def solve(tokens, contradictions):
  10.    if not tokens:
  11.       yield set()
  12.    else:
  13.       tokens = set(tokens)
  14.       t = tokens.pop()
  15.       for solution in solve(tokens - contradictions[t], contradictions):
  16.          yield solution | set([t])
  17.       if contradictions[t] & tokens:
  18.          for solution in solve(tokens, contradictions):
  19.             if contradictions[t] & solution:
  20.                yield solution
  21.  
  22. print list(solve(token_list, contradictions))
RAW Paste Data
Top