progs/sudoku.scala
changeset 325 ca9c1cf929fa
parent 321 7b0055205ec9
child 329 8a34b2ebc8cc
equal deleted inserted replaced
324:2969ee4a6cee 325:ca9c1cf929fa
    49 def search(game: String): List[String] = {
    49 def search(game: String): List[String] = {
    50   if (isDone(game)) List(game)
    50   if (isDone(game)) List(game)
    51   else 
    51   else 
    52     candidates(game, emptyPosition(game)).par.
    52     candidates(game, emptyPosition(game)).par.
    53       map(c => search(update(game, empty(game), c))).toList.flatten
    53       map(c => search(update(game, empty(game), c))).toList.flatten
       
    54 }
       
    55 
       
    56 def search1T(games: List[String]): Option[String] = games match {
       
    57   case Nil => None
       
    58   case game::rest => {
       
    59     if (isDone(game)) Some(game)
       
    60     else {
       
    61       val cs = candidates(game, emptyPosition(game))
       
    62       search1T(cs.map(c => update(game, empty(game), c)) ::: rest)
       
    63     }
       
    64   }
    54 }
    65 }
    55 
    66 
    56 // a list of hard games according to Andrew Coles and Peter Norvig
    67 // a list of hard games according to Andrew Coles and Peter Norvig
    57 
    68 
    58 val hard_games = 
    69 val hard_games =