Want more features on Pastebin? Sign Up, it's FREE!
Guest

function did not work correctly

By: a guest on Jun 30th, 2010  |  syntax: Python  |  size: 0.57 KB  |  views: 61  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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))
clone this paste RAW Paste Data