コード例 #1
0
ファイル: solve.py プロジェクト: weaming/sudoku
def search(values, multi=False):
    """Using depth-first search and propagation, try all possible values."""
    if values is False:
        # Failed earlier
        return False
    if all(len(values[s]) == 1 for s in squares):
        # Solved!
        return values
    # Chose the unfilled square s with the fewest possibilities
    n, s = min((len(values[s]), s) for s in squares if len(values[s]) > 1)
    if multi:
        return get_all(search(assign(values.copy(), s, d)) for d in values[s])
    else:
        return some(search(assign(values.copy(), s, d)) for d in values[s])
コード例 #2
0
ファイル: log.py プロジェクト: nicLucian/pytis
 def _is_accepted(self, kind, message, data):
     if not __debug__ and kind == DEBUG:
         return False
     import config
     if kind in config.log_exclude:
         return False
     if kind == DEBUG:
         if self._module_filter and not self._module.startswith(self._module_filter):
             return False
         if ((self._class_filter and
              (self._class_ is None or
               not some(lambda c: issubclass(self._class_, c), self._class_filter)))):
             return False
     return True
コード例 #3
0
 def _is_accepted(self, kind, message, data):
     if not __debug__ and kind == DEBUG:
         return False
     import config
     if kind in config.log_exclude:
         return False
     if kind == DEBUG:
         if self._module_filter and not self._module.startswith(
                 self._module_filter):
             return False
         if ((self._class_filter
              and (self._class_ is None
                   or not some(lambda c: issubclass(self._class_, c),
                               self._class_filter)))):
             return False
     return True
コード例 #4
0
 def test_some(self):
     T = True
     F = False
     self.assertFalse(util.some(util.identity, ()))
     self.assertTrue(util.some(util.identity, (T,)))
     self.assertFalse(util.some(util.identity, (F,)))
     self.assertTrue(util.some(util.identity, (F, T)))
     import operator
     self.assertTrue(util.some(operator.and_, (T, T), (T, F)))
     def all3(x,y,z):
         return x and y and z
     self.assertFalse(util.some(all3, (T, T), (T, F), (F, T)))